2011-09-23 3 views
0

je ce code:Comment fermer tous les marqueurs ouverts?

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

et comment vous pouvez le voir, j'ai un écouteur pour chaque marqueur!

Maintenant, quand je clique sur un marqueur, je voudrais fermer tout le marqueur (en fait un seul, l'ouvert précédemment). Comment puis-je le faire sur l'API Google Maps 3?

Répondre

1

définir le plan du marqueur à null:

marker.setMap(null); 
Questions connexes