2011-09-23 45 views
0

我有這樣的代碼:如何關閉所有打開的標記?

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

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

,你如何看,我有每個標記的監聽器!

現在,當我點擊一個標記時,我想關閉所有標記(實際上只有一個,之前打開過)。

如何在Google Maps API 3上執行此操作?

回答

1

設置標記的地圖到null:

marker.setMap(null); 
相關問題