2012-02-09 157 views
0

我从谷歌地图API第2版网页转换为3 V2我可以做下面的删除标记 -谷歌地图API V3移除标记

GEvent.addListener(map, "singlerightclick", function(pixel,tile, marker) { 
if(marker){ 
    if (confirm("Deselect " + marker.title +" and remove from Map?")){ 
    map.removeOverlay(marker); 
    window.status = "Deselected>" + marker.title + "<" ;}} 
    }); 

不过,我现在已经改变了代码添加标记并不能弄清楚如何选择合适的鼠标点击从markerarray标记,我现在用的是下面的代码添加标记

function createRedMarker(Lat,Lang,html,atitle) { 
    var latlng = new google.maps.LatLng(Lat,Lang); 
    var marker = new google.maps.Marker({ 
position: latlng, 
    map: map, 
    title: atitle, 
    icon:redmarker, 
shadow:mshadow 
}); 
google.maps.event.addListener(marker, "click", function() {infowindow.setContent(html); infowindow.open(map,marker);});  
markersArray.push(marker); 
    } 

有没有可能有人给我如何某些指针为此

+0

你可以发布一个链接到住的代码?或者把你的代码放在JS Fiddle上? – andresf 2012-02-10 04:22:03

回答

1

您需要添加另一个事件侦听器右击,第一事件侦听器的下方。所以,你的代码看起来就像这样:

... 
google.maps.event.addListener(marker, "click", function() {infowindow.setContent(html); infowindow.open(map,marker);}); 

google.maps.event.addListener(marker, "rightclick", function() { 
if (confirm("Deselect " + marker.title +" and remove from Map?")){ 
    marker.setMap(null); 
    window.status = "Deselected>" + marker.title + "<" ;}} 
}); 
markersArray.push(marker); 
...