开发者

How to close all opened markers?

I have this code :

var markers = new Array();

markers[0] = new google.maps.Marker({
    position: new google.maps.LatLng(45.910078, 10.838013),
    map: map, 
    title: "Data 1"
});

google.maps.event.addListener(markers[0], 'click', function() {
    var infowindow = new google.maps.InfoWindow({
        content: $('#map_info_window_id').html()
    });

    infowindow.open(map, markers[0]);
});开发者_JAVA百科

markers[1] = new google.maps.Marker({
    position: new google.maps.LatLng(46.176086, 11.064048),
    map: map,
    title: "Data 2"
});

google.maps.event.addListener(markers[1], 'click', function() {
    var infowindow = new google.maps.InfoWindow({
        content: $('#map_info_window_id').html()
    });

    infowindow.open(map, markers[1]); 
});

and how you can see, I have a listener for each marker!

Now, when I click on a marker, I'd like to close all marker (in fact only one, the previously opened).

How can I do it on Google Maps API 3?


set the map of the marker to null:

marker.setMap(null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜