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?

    1 Comment

  1. satyanarayana
    March 5, 2016
    Reply

    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 *

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...