Zoltan
Zoltan

Reputation: 43

Android remove MarkerOptions(!) from Google maps

I'm adding my position to map using MarkerOptions as follows:

userMarker = new MarkerOptions().position(latLng).title("Current Location");
mMap.addMarker(userMarker);

How could it remove it from the map?

Back in the old days, Marker Class had a remove() method, but MarkerOptions has nothing similar... I also checked mMap (which is a GoogleMap), but no luck... :(

Upvotes: 2

Views: 3258

Answers (3)

antonio
antonio

Reputation: 18262

The addMarker() method returns a Marker object that you can work with:

userMarker = new MarkerOptions().position(latLng).title("Current Location");
Marker myMarker = mMap.addMarker(userMarker);

And then remove your Marker doing

myMarker.remove();

Upvotes: 8

Bruno Andrade
Bruno Andrade

Reputation: 281

The Marker class has a remove method. Simply call: marker.remove()

Upvotes: 0

Eenvincible
Eenvincible

Reputation: 5626

It appears that MarkerOptions class has a few methods that could help you like:

public MarkerOptions visible(boolean visible);

This basically sets visibility status of your marker.

MarkerOptions updatedMarker = userMarker.visible(false);

It also returns the MarkerOptions object with its new status updated!

You can find more information on this by clicking here.

I hope this helps you!

Upvotes: 1

Related Questions