Encontrar la latitud y longitud de un sistema - Visual C#

     
     Ver Codigo
    usando  System.Device.Location; 
         latitud de cuerda privada ;  
        cadena privada  longitute;  
         vigilante privado GeoCoordinateWatcher =  nuevo  GeoCoordinateWatcher (); 
         Form1 público () 
        { 
            InitializeComponent (); 
        } 
        Private void  button1_Click (  remitente de objeto , EventArgs e)  
        { 
            textBox1.Text = latitud; 
            textBox2.Text = longitute; 
        } 
        private void  Watcher_StatusChanged (  remitente del objeto , GeoPositionStatusChangedEventArgs e) 
        // Buscar ubicación geográfica  del dispositivo  
            { 
                tratar 
                { 
                    if  (e.Status == GeoPositionStatus.Ready) 
                    { 
                        // Muestra la latitud y longitud. 
                        if  (observador.Posición.Ubicación.IsUnknown) 
                        { 
                            latitud =  "0" ; 
                            longitute =  "0" ; 
                        } 
                        más 
                        { 
                            latitude = watcher.Position.Location.Latitude.ToString (); 
                            longitute = watcher.Position.Location.Longitude.ToString (); 
                        } 
                    } 
                    más 
                    { 
                        latitud =  "0" ; 
                        longitute =  "0" ; 
                    } 
                } 
                captura  (excepción) 
                { 
                    latitud =  "0" ; 
                    longitute =  "0" ; 
                } 
            } 
        privado vacío  Form1_Load (  remitente del objeto , EventArgs e)  
        { 
            vigilante =  nuevo  GeoCoordinateWatcher (); 
            // Captura el evento StatusChanged. 
            watcher.StatusChanged + = Watcher_StatusChanged; 
            // Inicia el observador. 
            watcher.Start (); 
        } 
        }  
     
Codigo se encuentra en la web del programador



Comentarios