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... :(
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();
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With