The blockage of the direct signal by high-rise buildings degrades the positioning performance of the global navigation satellite system (GNSS) in urban canyons. Traditional methods usually distinguish the line-of-sight (LOS), and non-line-of-sight (NLOS) signals using the satellite’s elevation angle or signal strength to mitigate the issue, which cannot obtain satisfactory classification accuracy in complex urban environments. Recently, machine learning-based methods using GNSS measurements have been developed to improve GNSS signal classification. However, dynamic changes in environments and the limited features from the measurements raise a challenge to the classification performance of algorithms. To address the above issues, a transformerbased deep learning model in this paper is proposed for LOS and NLOS signal classification. The innovation of our proposed model is using the self-attention mechanism to construct the indirect environment interaction for learning the representation of environmental information. First, the measurements of captured satellites in the same epoch will be fed into the model. The model’s feature extraction layer can learn the fundamental representation. Then, the self-attention module can construct the indirect environment interaction by computing the relevance between the satellites. Finally, the module’s output is transferred to the output layer for classification. A comparative experimental study is conducted with real-world data collected in urban canyons. The results demonstrate that our model can keep more than 90% classification accuracy while support vector machine (SVM) and multilayer perception (MLP) decline to about 80% with the sites increasing.