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?

Pin It

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

  1. hi iam developing maps for windows phone my geo location, but it will show default US location did not show my location
    any one please help , i need urgent this projects
    my Projects is Destination Alert on Windows phone Maps

Leave a Reply

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