There is a growing demand for localization of illegal signal sources, aiming to guarantee the security of urban electromagnetic environment. The performance of traditional localization methods is limited due to the non-line-of-sight (NLOS) propagation and sparse layouts of sensors. In this paper, a deep learning-based localization method is proposed to overcome these issues in urban scenarios. Firstly, a model of electromagnetic wave propagation considered with geographic information is proposed to prepare reliable datasets for intelligent cognition of urban electromagnetic environment. Then, this paper improves an hourglass neural network which consists of downsampling and upsampling layers to learn the propagation features from sensing data. The core modules of VGG and ResNet are, respectively, utilized as feature extractors in downsampling. Moreover, this paper proposes a weighted loss function to expand the attention on position features, in order to improve the performance of localization with sparse layouts of sensors. Representative numerical results are discussed to assess the proposed method. ResNet-based extractor performs more efficiently than VGG-based extractor, and the proposed weighted loss function increases the localization accuracy by more than 50%. Additionally, the established geographic model supports qualitative and quantitative evaluation of the robustness with varied degree of NLOS propagation. Compared with other deep learning-based algorithms, the proposed method presents the more robust and superior performance under severe NLOS propagation and sparse sensing conditions.