I'm share the topic of how to find out Latitude and longitude of a system by win form in C#.
Some points here:
Some points here:
- This only works in .NET Framework 4.0 or later and Windows 7 or later.
- The Location API is defined in the System.Device DLL so add a reference to that library. The code includes the following using directive to make using the Location API easier.
- using System.Device.Location;
- private string latitude;
- private string longitute;
- private GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- textBox1.Text = latitude;
- textBox2.Text = longitute;
- }
- private void Watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e) // Find GeoLocation of Device
- {
- try
- {
- if (e.Status == GeoPositionStatus.Ready)
- {
- // Display the latitude and longitude.
- if (watcher.Position.Location.IsUnknown)
- {
- latitude = "0";
- longitute = "0";
- }
- else
- {
- latitude = watcher.Position.Location.Latitude.ToString();
- longitute = watcher.Position.Location.Longitude.ToString();
- }
- }
- else
- {
- latitude = "0";
- longitute = "0";
- }
- }
- catch (Exception)
- {
- latitude = "0";
- longitute = "0";
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- watcher = new GeoCoordinateWatcher();
- // Catch the StatusChanged event.
- watcher.StatusChanged += Watcher_StatusChanged;
- // Start the watcher.
- watcher.Start();
- }
- }
The accuracy of the location depends on the data available to the computer. If the computer has GPS (many phones and tablets do), this may be quite accurate. If the computer doesn’t have GPS (most desktop systems don’t have it), the API may use wi-fi triangulation or some other method, which may be less accurate.

rajendra singhPosted Apr 26, 2017, 1:36 AM
Can we use this in mvc
Adil AbbyyC)Posted Jun 8, 2016, 2:48 AM
Both latitude and longitude appears to be zero all the time. Any suggestion?
Munesh SharmaPosted May 22, 2016, 8:30 PM
nice