Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If marker.setMap == null do something

I want to implement something by Google maps and I need to know if setMap is alreay set or is null. How can I implement something like this:

if (marker.setMap == null)
{
    marker.setMap(map);
}
like image 303
Sponge Bob Avatar asked Nov 24 '25 03:11

Sponge Bob


1 Answers

You have to call the getMap function, not check if the setMap function is null. This will toggle the marker:

if (marker.getMap() == null) marker.setMap(map);
else marker.setMap(null);

or even

if (!marker.getMap()) marker.setMap(map);
else marker.setMap(null);
like image 112
geocodezip Avatar answered Nov 26 '25 21:11

geocodezip