Chapter 21. Using GPS
Windows Phone 7 Assisted GPS enables you to create applications that provide the user with relevant location-aware data, enhancing the user experience. As an example, if you are developing an application for a large coffee shop chain that has stores at 100 locations throughout a large metropolitan area, you can use the current location of the phone to display the five nearest locations. To provide this experience you might use a combination of the Location Service and the Bing Maps Service.
GETTING DATA FROM THE LOCATION SERVICE API
The Location Service API enables you to access a single API to retrieve information about the current location of the Windows Phone 7 device. Without this API you would have to write code to check for and use location data from three possible sources; the current GSM cell ID, the access point for WiFi (if WiFi is in use), and GPS data. With the Location Service API you need only make one call to the API to retrieve the current location.
Obtaining the Geographic Coordinates for a Location
The Location Service API takes care of the task of checking to see which of the aforementioned sources is able to provide data; it determines the best source to use and returns the data. To use the Location Service API you must first add a reference to the System.Device
component to your application. Then you will need to add a using directive to the top of the class file for the page that will be using the Location Service:
using System.Device.Location; ...
Get Windows® Phone 7 Application Development 24-Hour Trainer 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.