Getting the Current Location

To get the current location, you create an instance of Geolocator and call GetGeopositionAsync:

Geolocator locator = new Geolocator(); try {   Geoposition position = await locator.GetGeopositionAsync();   ... } catch (UnauthorizedAccessException) {   // Location is not enabled for this app }

Because GetGeopositionAsync prompts the user with a “Can [app name] use your location?” prompt the first time your app calls it, this call must be made on the UI thread. If the user chooses “Block” or later disables the Location capability for your app via the Settings pane, GetGeopositionAsync throws an UnauthorizedAccessException.

The data may be cached for performance reasons, so an overload of ...

Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.