How to get the Current Geo Coordinates in Windows Phone using C# ?

The GeoCoordinateWatcher class lets you to get the Geo Coordinates in Windows Phone . It is part of the Location Services which lets you to retrieve the current location (latitude,longitude) , speed etc.

How to get the Current Geo Coordinates in Windows Phone using C# ?

To use the GeoCoordinateWatcher to retreive the GPS location , you should add the reference to the System.Devices.Location namespace.

Below is a sample source code that demonstrates the usage of the GeoCoordinateWatcher class to get the current Geo Coordinates in Windows Phone using C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.Device.Location;

namespace PhoneApp1
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            GeoCoordinateWatcher GeoCoordinater;
            GeoCoordinater = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
            GeoCoordinater.PositionChanged += new EventHandler<GeoPositionChangedEventArgs>(watcher_PositionChanged);
            GeoCoordinater.Start();
        }

        void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs e)
        {
            MessageBox.Show("Latitude = " + e.Position.Location.Latitude + " : Longitude = " + e.Position.Location.Longitude);
        }
    }
}
How to get the Current Geo Coordinates in Windows Phone using C# ?
How to get the Current Geo Coordinates in Windows Phone using C# ?

    1 Comment

  1. patel
    December 6, 2013
    Reply

    does this use internet or just use gps ???

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...