Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps V2 - Android - Get a list of Markers

I'm trying to get a list Markers(using GMaps V2 for Android) similar to the getOverlays() method I used in GMaps V1.1 for Android here:

private MapView mapView; 

mapView.getOverlays().add(overlay);

How can I do something similar to what I did above but with Markers?

Any help would be appreciated.

like image 585
user268397 Avatar asked May 03 '13 21:05

user268397


2 Answers

How can I do something similar to what I did above but with Markers?

When you call addMarker(), save the resulting Marker object in a collection of your choice (e.g., ArrayList<Marker>).

like image 129
CommonsWare Avatar answered Nov 12 '22 12:11

CommonsWare


Alternative to the correct answer from CommonsWare would be using Android Maps Extensions, which adds getMarkers() function to GoogleMap.

Btw. mapView.getOverlays().add(overlay) code from Maps V1 is a very bad design choice. You should not give out List for modification. So this will not work with Extensions library.

like image 42
MaciejGórski Avatar answered Nov 12 '22 12:11

MaciejGórski