Chapter 11. Location, location, location
This chapter covers
- Working with LocationProvider and LocationManager
- Testing location in the emulator
- Receiving location alerts with LocationListener
- Drawing with MapActivity and MapView
- Looking up addresses with the Geocoder
Accurate location awareness makes a mobile device more powerful. Combining location awareness with network data can change the world—and Android shines here. Other platforms have gained similar abilities in recent years, but Android excels with its easy-to-use and popular location API framework based on Google Maps.
From direct network queries to triangulation with cell towers and even satellite positioning via GPS, an Android-powered device has access to different types of LocationProvider classes that allow access to location data. Various providers supply a mix of location-related metrics, including latitude and longitude, speed, bearing, and altitude.
Developers generally prefer to work with GPS because of its accuracy and power. But some devices may not have a GPS receiver, and even GPS-enabled devices can’t access satellite data when inside a large building or otherwise obstructed from receiving the signal. In those instances the Android platform provides a graceful and automatic fallback to query other providers when your first choice fails. You can examine provider availability and hook into one or another using the LocationManager class.