Windows Phone 8.1 and Windows Runtime Apps How to #17 – Detect current User Location

This article will demonstrate in simple steps in how to detect the current location of the use from a Windows Phone 8.1 App.

Retrieving the current location in Windows Phone 8.1 is similar to retrieving the location in Windows Phone 8 . The Geolocator class is used to retreive the current location using the GetGeoPositionAsync method.

How to Detect the Current User Location in a Windows Phone 8.1 ?

Follow the below steps to detect the current location of the user from a Windows Phone 8.1 App .

1. Launch Visual Studio 2013 and Open your Windows Phone 8.1 project.

2. Open the Package.appxmanifest file from the project’s solution explorer . In the Package.appxmanifest designer , select the capabilities tab and enable Location capability.

image

2. Write code to retreive the current location using the Geolocation’s GetGeoPositionAsync method to get the Coordinates and display the latitude and longitude as shown below.

async private void txtLocation_Click(object sender, RoutedEventArgs e)
{
    Geolocator geo = new Geolocator();
    Geoposition position = await geo.GetGeopositionAsync();
    txtLocation.Text = "Latitude: " + position.Coordinate.Point.Position.Latitude.ToString() + 
               " Longitude: " + position.Coordinate.Point.Position.Longitude;
}

Just create an instance of the Geolocator class and invoke the GetGeopositionAsync method . This will return the Geoposition which contains the Coordinates from which the latitude and longitude can be detected.

SNAGHTML14d509ef

Also , dont forget to enable the Location services via the Settings –> Location app in your Windows Phone 8.1 (or) Emulator to get the current location .

Leave A Reply

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

You May Also Like

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...