2012-03-03 85 views
0

我有一个infowindow有一个“擦除条目”按钮,单击时,删除标记并关闭信息窗口。 当我点击“擦除条目”按钮时,它会删除标记并关闭infowindow,但它也会在地图上注册另一个点击,并且我不知道为什么,并且这会让我发疯。单击infowindow中的按钮导致地图点击注册谷歌地图API v3

有没有人碰到过这个问题? 我很喜欢JavaScript,所以任何关于实现的建议都会很棒。谢谢。下面 是的我在做什么伪/摘要:

 //global variable to keep track of which was the last marker clicked 
     var lastMarkerJustClicked; 

     function load(){ 
      //create the map and everything, add the following listener 
      google.maps.event.addListener(map, 'click', function (event) { 
       //firebug has been telling me that after i click "erase entry" and my marker is removed and my infowindow closes, i end up here 
       makeParticularMarker(event.latLng); 
      }); 
     } 

     function makeParticularMarker(marker_parameter) { 
      var markerLocation = //do stuff to get the right marker parameter 
      var markerWithLocation = new google.maps.Marker({ 
       position: markerLocation, 
       map: map 
      }); 
      var html = "<input type='button' value='Erase Entry' onclick=eraseEntry() />" 
      var markerWithInfo = createMarkerWithHTML(markerWithLocation, html); 
     } 

     function createMarkerWithHTML(markerWithLocation, html) { 
      var markerWithInfo = google.maps.event.addListener(markerWithLocation, 'click', function() { 
       infoWindow.setContent(html); 
       infoWindow.open(map, markerWithLocation) 
       lastMarkerJustClicked=markerWithLocation; 
      }); 
     } 

     function eraseEntry() { 
      infoWindow.close() 
      lastMarkerJustClicked.setMap(null); 
     } 

回答

相关问题