Skip to content

Instantly share code, notes, and snippets.

@SajjadArifGul
Created December 12, 2015 16:55
Show Gist options
  • Save SajjadArifGul/0a2d365ea6a8f5cb0aaa to your computer and use it in GitHub Desktop.
Save SajjadArifGul/0a2d365ea6a8f5cb0aaa to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Device.Location;
namespace LongLat
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// The coordinate watcher.
private GeoCoordinateWatcher Watcher = null;
// Create and start the watcher.
private void Form1_Load(object sender, EventArgs e)
{
// Create the watcher.
Watcher = new GeoCoordinateWatcher();
// Catch the StatusChanged event.
Watcher.StatusChanged += Watcher_StatusChanged;
// Start the watcher.
Watcher.Start();
}
// The watcher’s status has change. See if it is ready.
private void Watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
if (e.Status == GeoPositionStatus.Ready)
{
// Display the latitude and longitude.
if (Watcher.Position.Location.IsUnknown)
{
txtLat.Text = "Cannot find location data";
}
else
{
txtLat.Text = Watcher.Position.Location.Latitude.ToString();
txtLong.Text = Watcher.Position.Location.Longitude.ToString();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment