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’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...