Based on the Kharzeev-McLerran-Warringa (KMW) model that estimates strong electromagnetic (EM) fields generated in relativistic heavy-ion collisions, we generalize the formulas of EM fields in the vacuum by incorporating the longitudinal position dependence, the generalized charge distributions and retardation correction. We further generalize the formulas of EM fields in the pure quark-gluon plasma (QGP) medium by incorporating a constant Ohm electric conductivity and also during the realistic early-time stages QGP evolution by using a time-dependent electric conductivity. Using the extended KMW model, we observe a slower time evolution and a more reasonable impact parameter $b$ dependence of the magnetic field strength than those from the original KMW model in the vacuum. The inclusion of medium effects by using the lattice data helps to further prolong the time evolution of magnetic field, such that the magnetic field strength during the realistic QGP evolution at thermal freeze-out time can meet the $1sigma$ bound constrained from experimentally measured difference in global polarizations of $Lambda$ and $bar{Lambda}$ hyperons in Au+Au collisions at top RHIC energy. These generalized formulations in the extended KMW model will be potentially useful for many EM fields relevant studies in heavy-ion collisions, especially at lower colliding energies and for various species of colliding nuclei.