Windows Phone 8 Dev Guide – Retrieving the Current Location

If you want to retreive the current location from your Windows Phone app , you can use the GetGeopositionAsync method that is defined inn the Windows.Devices.Geolocation.Geolocator class.

How to Get the Current Location from Windows Phone 8 ?

To use the Location and Maps API in your Windows Phone 8 app , it is necessary to set the below capabilities in the WMAppManifest.xml GUI Capabilities tab of your project.

  • ID_CAP_MAPS
  • ID_CAP_LOCATION

Just create an instance of the Geolocator class and call the GetGeopositionAsync() method to return the Geoposition . The resulting Geoposition’s latitude and longitude can be used to identify the current location which can later be used to display on the map.

Below is a code snippet demonstrating the usage of the GetGeopositionAsync to get the current location.

Geolocator GKlocator = new Geolocator();    
GKlocator.DesiredAccuracy = PositionAccuracy.High; 
Geoposition position = await GKlocator.GetGeopositionAsync(); 
MessageBox.Show(position.Coordinate.Latitude + " , " + position.Coordinate.Longitude);
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply