O'Reilly logo

Windows® Phone 8 Unleashed by Daniel Vaughan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Centering the Map to the Phone’s Current Location

The sample’s MapViewModel class contains a GetLocation method that uses the Geolocator class, which is new to Windows Phone 8, to retrieve the phone’s current location (see Listing 18.1).

The GetPositionAsync method is an awaitable method that allows you to retrieve the phone’s last known location without blocking the UI thread.

When attempting to call the Geolocator object’s GetGeopositionAsync method, if location is disabled in the phone’s settings, an UnauthorizedAccessException is raised.

For more information on location tracking and the Geolocator class, see Chapter 17, “Building Location Aware Apps.”

LISTING 18.1. MapViewModel.GetLocation Method

async Task ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required