How to remove single marker using Google Maps V2?

AndroidGoogle MapsAndroid MapviewGoogle Maps-Android-Api-2

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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

Marker marker = map.addMarker(..);

The Marker class has a remove method:

Solution 2 - Android

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

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

Solution 3 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexey ZakharovView Question on Stackoverflow
Solution 1 - AndroidAlexey ZakharovView Answer on Stackoverflow
Solution 2 - AndroiddouarbouView Answer on Stackoverflow
Solution 3 - AndroidDiscDevView Answer on Stackoverflow