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

In this post, you will learn about sync provider notifications in Windows 11 and how to disable or enable it...
In this tutorial, let’s learn how to enable or disable the startup sound in Windows 11. By default, when Windows...
The CameraCaptureTask allows the Windows Phone 7 App to launch the Camera Application . This will be useful when the...