Location for Windows Phone 8
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
With Windows Phone 8, you can create applications that utilize the phone’s physical location. Scenarios for location-aware applications include checking the user into a web service using the user’s instantaneous location and tracking the user’s location as it changes over a period of time. The location data the phone provides comes from multiple sources including GPS, Wi-Fi, and cellular. There are two different sets of APIs that can be used to incorporate location data into your application. This topic will help you decide which location API is right for your application.
The Windows Runtime location API is supported for both Windows Phone 8 and Windows Phone 8.1 apps. This topic is part of the Windows Phone 8 documentation. To view the Windows Phone 8.1 documentation for this feature, which includes information on developing for both phone and PC, see Detecting Geolocation.
The Windows Phone Runtime Location API
The Windows Phone Runtime location API is new in Windows Phone 8. It has the following features:
Accessible from managed and native code. If you are writing a Direct3D app application, you must use this API for location. If you are creating a managed app, it is recommended that you use this API as well.
Greater support for one-shot location acquisition. The API allows the app to specify the desired accuracy of the location result as well as the maximum time desired for acquiring the result in order to balance accuracy and responsiveness. It is recommended that applications use one-shot location when tracking isn’t required. This results in better battery life and, therefore, a better user experience.
When tracking location, apps can request to receive location updates after a specified time interval or after the device has moved at least a specified distance from the previous location.
Convergent with Windows 8. Although there are minor differences between the two platforms, this API will allow you to reuse most of your location code if you are targeting both the phone and the desktop.
For information on using the Windows Phone Runtime location API in your application, see the following topics.
How to continuously track the phone's location for Windows Phone 8
How to run location-tracking apps in the background for Windows Phone 8
To download a sample app that demonstrates getting the phone’s current location, tracking the phone’s location, and tracking location in the background, see Location Sample for Windows Phone 8.
The .NET Location API
The .NET location API was introduced in Windows Phone, but is fully supported on Windows Phone 8. It is recommended that you use this API if you are targeting both Windows Phone OS 7.1 and Windows Phone 8 devices and you want to reuse code between the applications. Otherwise, it is recommended that you use the new Windows Phone Runtime interface. For more information on developing apps using the .NET location API, see .NET Location API for Windows Phone 8.