34. Maps
In this chapter, you will go one step further with LocatrFragment. In addition to searching for a nearby
image, you will find its latitude and longitude and plot it on a map.
Importing Play Services Maps
Before you get started, you need to import the mapping library. This is another Play Services
library. Open the project structure window and add this dependency to your app module:
com.google.android.gms:play-services-maps:10.0.1.
Mapping on Android
As enjoyable as it is to have data that tells you where your phone is, that data begs to be represented
visually. Mapping was probably the first truly killer app for smartphones, which is why Android has
had mapping since day one.
Mapping is big, complicated, and involves an entire support system of servers to provide base map
data. Most of Android can stand alone as part of the Android Open Source Project. Maps, however,
cannot.
So while Android has always had maps, maps have also always been separate from the rest of
Android’s APIs. The current version of the Maps API, version 2, lives in Google Play Services along
with the Fused Location Provider. So to use it, the same requirements apply as the ones you saw in the
section called Google Play Services in Chapter 33: You have to either have a device with the Play Store
installed or an emulator with the Google APIs.
If you are making something with maps and happen to flip straight to this chapter, make sure that you
have followed the steps from the previous chapter before you start:
- ensure that your device supports Play Services
- import the appropriate Play Services library
- use GoogleApiAvailability at an appropriate entry point to ensure that an up-to-date Play Store
app is installed