Google Maps V2 - Android - Get a list of Markers

偶尔善良 提交于 2019-11-26 20:49:33

问题


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.


回答1:


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>).




回答2:


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.



来源:https://stackoverflow.com/questions/16367594/google-maps-v2-android-get-a-list-of-markers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!