google-maps - Google Maps API V3 - 向所有标记添加事件监听器?

标签 google-maps google-maps-api-3

必须有一种方法可以为所有标记添加一个监听器,目前我正在使用一个感觉非常错误的循环为每个标记添加一个监听器......

这感觉不对:

google.maps.event.addListener(unique_marker_id, 'click', function(){
    //do something with this marker...                   
});   

最佳答案

在两个 MarkerMarkerWithLabel情况下,您不妨使用 关键字来引用事件处理程序附加到的对象:

google.maps.event.addListener(marker, 'click', function () {
   // do something with this marker ...
   this.setTitle('I am clicked');
});

这里指的是特定的标记对象。

关于google-maps - Google Maps API V3 - 向所有标记添加事件监听器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6611634/

相关文章:

javascript - 如何在Infobox中使用AjaxUrl属性(ExtInfoWindow)?

javascript - Google map Api key 如何在我的 html 中工作?

google-maps - 在谷歌地图中检测按键

google-maps - Google Maps v3 中不滚动的最大信息窗口宽度大小

javascript - Google Maps Javascript API 正在返回静态图像

xcode - 是否可以使用mapkit创建自定义 map ?

google-maps-api-3 - 有没有办法使覆盖对象不可点击?

javascript - 如何将 GEvent.callbackArgs 移至 V3

javascript - 如何在vue js中使用@click inside google maps infowindow触发一个函数?

javascript - 等待使用 getCurrentPosition 达到准确度阈值