Recipe 7.5 Adding Markers to the Map
You want to add markers to the map indicating the current location, or locations of interest.
In the previous recipe, you learned how to make the Google Maps navigate to a particular location. Doing so pans the map, with the location you are navigating to be displayed at the center. A much more useful visual cue to the user would be a marker (commonly known as the pushpin) on the map so that the location is immediately clear to the user. The following sections show you the various ways to add this.
Solution Part 1: Displaying a Marker at the Current Location
One common request from developers is the capability to display the current location of the user without resorting to using the LocationManager class as described in Chapter 8, “Location-Based Services,” Recipe 8.1.
To do so, you can use the MyLocationOverlay class. All you need is to do is create an instance of this class and then add it to the overlay lists of the MapView.
The following code snippet shows how to display the current location on the map using the MyLocationOverlay class:
package net.learn2develop.maps; import ...