문제

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);
}
도움이 되었습니까?

해결책

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);

다른 팁

You can't do that, because marker.setMap removes the reference to the map.
Instead, use marker.setVisible(false) to hide your marker, then, simply test visibility of your marker. setVisible just hides the marker, but the reference to the map is not lost.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top