Step 1: Verify that location is enabled

Before your app can access location, Location must be enabled on the device. In the Settings app, check that the following location privacy settings are turned on:

Location for this device... is turned on (not applicable in Windows 10 Mobile)

The location services setting, Location, is turned on

Under Choose apps that can use your location, your app is set to on

Step 2: Enable the location capability

Double click on package.appxmanifest in Solution Explorer and select the Capabilities tab. Then check Location in the Capabilities list. This adds the Location device capability to the package manifest file.

Step 3: Request access to the user's location

Important Starting in Windows 10, call the RequestAccessAsync before accessing the user’s location. At that time, your app must be in the foreground and RequestAccessAsync must be called from the UI thread. Until the user grants your app permission to their location, your app can't access location data.

The RequestAccessAsync method prompts the user for permission to access their location. The user is only prompted once (per app). After the first time they grant or deny permission, this method no longer prompts for permission. To help the user change location permissions after they've been prompted, we recommend providing a link to the location settings as demonstrated later in this topic.

Step 4: Get the user's location and register for changes in location permissions

The GetGeopositionAsync method performs a one-time reading of the current location. Here, a switch statement is used with accessStatus (from the previous example) to act only when access to location is allowed. If allowed, the code creates a Geolocator object, registers for changes in location permissions, and requests the users location.

Step 5: Handle changes in location permissions

The Geolocator object triggers the StatusChanged event to indicate that the user's location settings changed. That event passes the corresponding status via the argument's Status property (of type PositionStatus). Note that this method is not called from the UI thread and the Dispatcher object invokes the UI changes.

Step 6: Help the user change location settings

If the location settings don't allow your app to access the user's location, we recommend providing a convenient link to the location privacy settings in the Settings app. In this example, a Hyperlink control is used navigate to the ms-settings:privacy-location URI.