-1

我想将以下 2 个 google map V2 API 事件转换为 V3,但我一生都无法弄清楚该怎么做,有人可以给我一些指示吗?

    GEvent.addListener(map, "click", function(overlay, point){
    if (point != null) {
      window.status = "Click " + point.lat() + ", "+ point.lng();
    } 
          else if (overlay != null) 
        {
      window.status = "Overlay " + lastPoint.lat() + ", "+ lastPoint.lng();
    }
});
GEvent.addListener(map, "mousemove", function(point){
 lastPoint = point;
});
4

2 回答 2

1

尝试这个:

google.maps.event.addListener(map, 'click', function(event) {
  console.log(event.latLng);
});

“v3 事件侦听器中不存在覆盖参数。如果您在 v3 地图上注册点击事件,则回调只会在用户点击基本地图时发生。如果您需要对这些点击做出反应,您可以在可点击的覆盖上注册额外的回调. " - https://developers.google.com/maps/articles/v2tov3#events

于 2013-04-25T17:11:18.437 回答
0

如果您需要点击覆盖并让覆盖可点击,请从覆盖传播点击:

var map = new google.maps.Map(document.getElementById("mapcanvas"), mapOptions);

google.maps.event.addListener(map, 'click', function(event) {
    console.log(event.latLng);
});

google.maps.event.addListener(overlay, 'click', function(event) {
    google.maps.event.trigger(map, 'click', event);
});
于 2013-05-29T10:11:54.287 回答