What’s new in Location Tracking API for Windows Phone 8.0?

Windows Phone 8 brings forth a lot of new and improved APIs. One of the improved API is for location tracking. Let’s take a brief but closer look at these improvements,

GeoCoordinateWatcher replaced with Geolocator class

Earlier in Windows Phone 7.5 you had GeoCoordinateWatcher class available to location tracking but in Windows Phone 8.0 location tracking is exposed through Geolocator class.

Geolocator geolocator = new Geolocator();

Inclusion of GetGeoPositionAsync method

The new class has addition of an Async method that is particular useful if your application wants to retrieve location information only once. That is, earlier in Windows Phones 7.5 you were supposed to hook for PositionChanged event to identify location and then had to stop listening on GeoCoorindateWatcher class object but now you can simply call GetGeoPositionAsync.

Geoposition position = await geolocator.GetGeopositionAsync(

                 maximumAge: TimeSpan.FromMinutes(1), timeout: TimeSpan.FromSeconds(30)); 

Where maximumAge is “The maximum acceptable age of cached location data.”

Background Location Tracking Support

Windows Phone 8.0 handles background tracking. i.e. if an application needs to request location tracking using background agent, in WP 7.5 the result was cached however in the new API this limitation is handled and you can continue to retrieve updated result in background agent. That’s where the GetGeoPositionAsync method is particular helpful. Consider the clever use of maximumAge parameter in the background agent.

Note that if you are planning to place location tracking call in the background agent however, please make sure that there is a bug in Windows Phone 8.0 that “PeriodicTask fails to trigger if there is no network connectivity in WP8 (enable Airplane mode, or disable both cellular and wifi).

Comments (0)

Skip to main content