Subscribe to our YouTube Channel for more Videos

How to Get the Current Location and Display it on Map using MapsTask in WP8?


The GetGeoPositionAsync method of the Geolocator class can be used to get the Current Location from the Windows Phone 8.

In this blog post, let’s explore how to get the current location in Windows Phone 8 and display it on the Map using the MapsTask Launcher.

How to Get the Current Location and Display it on Map using MapsTask in WP8?

The Geolocator class is defined in the Windows.Devices.Geolocation namespace. To get the current location, just instantiate the Geolocator class and call the GetGeoPositionAsync method. Make sure that the ID_CAP_MAPS and ID_CAP_LOCATION capabilities are enabled in the WMAppManifest.xml file.

Below is a code snippet that get the current location using the Geolocator class and then displays it on the Map using MapsTask .

Geolocator Loc = new Geolocator();

Loc.DesiredAccuracy = PositionAccuracy.High;

Geoposition pos = await Loc.GetGeopositionAsync();

MapsTask mapTask = new MapsTask();

mapTask.ZoomLevel = 18;

mapTask.Center = new GeoCoordinate(pos.Coordinate.Latitude, pos.Coordinate.Longitude);

mapTask.Show();

The GetGeopositionAsync method of the Geolocator returns the Geoposition which has the latitude and longitude which is used to create the GeoCoordinate and then assign to the Center property of the Maps Task. When the Show method of the MapsTask is called, the built-in Maps Application is launched.

How to Get the Current Location and Display it on Map using MapsTask in WP8?

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.