How to remove specific marker on Android GoogleMap
When you add a marker on Map, you can store it into HashMap like this:
HashMap<YourUniqueKey,Marker> hashMapMarker = new HashMap<>();
Marker marker = googleMap.addMarker(markerOptions);
hashMapMarker.put(YourUniqueKey,marker);
At the time you want to delete particular marker just get your Maker by YourUniqueKey for that marker like this:
Marker marker = hashMapMarker.get(YourUniqueKey);
marker.remove();
hashMapMarker.remove(YourUniqueKey);
use setOnMarkerClickListener to do this!
the code is below:
mGoogleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
marker.remove();
return true;
}
});
once you click on a "Marker" you can remove it.