Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a particular marker from Google Map in Android

I add a marker on each map click, and I only want to see the last one.

I tried the following code:

if(marker!=null)
{
marker.visible(false);
marker=null;
}

marker=new MarkerOptions().position(latLng);
googleMap.addMarker(marker);

I see every marker even though I set it to invisible.

How can I remove after each click? I can't find any remove methods.

like image 561
Nestor Avatar asked Jan 29 '14 22:01

Nestor


1 Answers

Just keep a reference to the marker each time you do the click :

Marker marker = map.addMarker(MARKER_OPTIONS);

Then call remove() method :

marker.remove();
like image 160
S.Thiongane Avatar answered Nov 15 '22 05:11

S.Thiongane