有没有办法在google map v3上执行此操作?我在地图上有一个按钮,我想在第一次点击时显示标记,然后在第二个按钮上将它们从地图中删除。谢谢你提前。
//Add hotel's markers and infowindows to the map
google.maps.event.addDomListener(hotel, 'click', function() {
for (var i = 0; i < len; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(results.rows.item(i).lat,results.rows.item(i).long),
map: map,
icon : icons[1],
animation: google.maps.Animation.DROP,
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
//if we create the infowindow here, all the windows 'll stay shown
infowindow.setContent("<div style='background-color:red;'><h3>"+results.rows.item(i).nom+"</h3><br/><center>"+"<img src='"+results.rows.item(i).img+"' style='width:20px; height:20px;' /></center><br/></div>")
infowindow.open(map,marker);
}
})(marker,i));
}
});
答案 0 :(得分:0)
showMarkers
变量toggleMarkers
,并在单击按钮这是一个简单的例子:
var showMarkers = false;
function toggleMarkers() {
if (showMarkers === false) {
for (var i=0; i<markers.length; i++) {
markers[i].setMap(map);
}
showMarkers = true;
} else {
for (var i=0; i<markers.length; i++) {
markers[i].setMap(null);
}
showMarkers = false;
}
}