Karol
Karol

Reputation: 8053

Hiding & showing markers on event

google.maps.Marker.prototype.hide = function() 
{
    if (this.div_) 
    {
        this.div_.style.visibility = "hidden";
    }
};
google.maps.Marker.prototype.show = function() 
{
    if (this.div_) {
        this.div_.style.visibility = "visible";
    }
};

It doesnt cause any error. But it doesnt work while Im using it:

marker = new google.maps.Marker({
                map: map,
                draggable: false,
                position: latlng,
                title: 'some title'
            });

And now if someone change the zoom I want to trigger hiding marker:

google.maps.event.addListener(map, 'zoom_changed', function() {
            marker.hide();
});

But it doesnt work. Could someone help me resolve the problem?

Upvotes: 0

Views: 434

Answers (2)

herostwist
herostwist

Reputation: 3968

to hide a marker use marker.setMap(null);

to show again use marker.setMap(mymap);

EDIT:

forgot about setvisible. here's a working example: http://jsfiddle.net/herostwist/v9nmQ/1/

Upvotes: 1

Felix Kling
Felix Kling

Reputation: 817030

The API already contains such a method: setVisible. Either pass true or false.

Upvotes: 0

Related Questions