Google Maps API V3删除标记

时间:2012-02-09 21:08:05

标签: google-maps

我正在将Google Maps API v2中的网页转换为V2中的3我可以执行以下操作以删除标记 -

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

有人可以给我一些关于如何做到这一点的指示

1 个答案:

答案 0 :(得分: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); 
...
相关问题