How to remove single marker using Google Maps V2? [duplicate]

纵饮孤独 提交于 2019-12-20 08:34:04

问题


The only method that removes markers from map is clear. However it clears all markers from the map.

I want to remove only single marker or group of markers.

How could i achieve this?


回答1:


After adding the marker it is possible to obtain its reference:

Marker marker = map.addMarker(..);

The Marker class has a remove method:




回答2:


I got the same problem, so to fix it I'm doing

mMap = super.getMap();
map.clear();



回答3:


I wrote up a blog post on how to remove Markers when they are moved off the screen, and adding them again when they are on the screen. This is useful if you are trying to add thousands of Markers to a GoogleMap at the same time but don't want the performance to suffer as much as it would if they are all on the map at the same time. It uses the same method you detailed (calling remove() on a Marker).

Hiding and Showing on screen Markers with Google Maps Android API V2



来源:https://stackoverflow.com/questions/13702379/how-to-remove-single-marker-using-google-maps-v2

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