Chapter 15. Location and Map Applications

Not that long ago, GPS devices were either unavailable, expensive, or cumbersome. Today, almost every smartphone has a GPS receiver, and many digital cameras do, too. GPS is well on its way to becoming truly ubiquitous in devices. The organizations that provide map data are well aware of this trend. Indeed, OpenStreetMap exists and provides its “free, editable map of the world” in part because of the rise of consumer GPS devices; most of its map data was provided by enthusiasts. Google gets much of its data from commercial mapping services, but in Android, Google has been very driven by the availability of GPS receivers in Android devices. This chapter thus concentrates on the ins and outs of using Google Maps and OpenStreetMap in Android devices.

15.1 Getting Location Information

Ian Darwin

Problem

You want to know where you are.

Solution

Use Android’s built-in location providers.

Discussion

Android provides two levels of location detection. If you need to know fairly precisely where you are, you can use the FINE resolution, which is GPS-based. If you only need to know roughly where you are, you can use the coarse resolution, which is based on the location of the cell tower(s) your phone is talking to or in range of. The FINE resolution is usually accurate to a few meters; the coarse resolution may be accurate down to the building or city block in densely built-up areas, or to the nearest 5 or 10 kilometers in very lightly populated ...

Get Android Cookbook, 2nd Edition 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.