Recipe 7.5 Adding Markers to the Map
You want to add markers to the map indicating the current location, or locations of interest.
Solution
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 ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access