Chapter 13. Dude, Where's My Car?
WHAT'S IN THIS CHAPTER?
Understanding the Location API
How to look up your current location with the GeoCoordinateWatcher class
How to use the CivicAddressResolver class
Windows Phone 7 offers a Location API that allows you to determine your location in multiple ways, including GPS, WiFi lookup, and cell tower triangulation. This chapter prepares you for using that service.
UNDERSTANDING AND ACCESSING THE LOCATION API
The Location API is provided so that you don't have to worry about customizing your game or application for specific hardware configurations. This includes not needing to worry about the specifics of how the data is acquired (via GPS, cell tower, and so on).
Everything you need to access your phone's location is stored within the System.Device .Location
namespace. You will be concerned with three types of data in this chapter: CivicAddress, GeoCoordinate
, and GeoPosition
.
Unfortunately, if you don't have a phone, you'll be unable to test all the examples presented in this chapter as intended. The Emulator has no means of acquiring actual GPS data.
BEST PRACTICES FOR USING LOCATION SERVICES
In this chapter, you will learn several different ways to interact with the Location API inside your game or app. What follows are some best practices when dealing with location data.
Asking Permission
When using any of the methods presented in this chapter in your app or game, you must ask the user's permission to get his or her location. Failure to do so can ...
Get Professional Windows® Phone 7 Game Development: Creating Games using XNA Game Studio 4 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.