Google Maps API V3 - 将事件侦听器添加到所有标记? [英] Google Maps API V3 - add event listener to all markers?

查看:103
本文介绍了Google Maps API V3 - 将事件侦听器添加到所有标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  google.maps.event.addListener(unique_marker_id,'click',function(){
//用这个标记做些什么...
});


解决方案

code>和 MarkerWithLabel 的情况下,您可以使用 this 关键字将对象其中事件处理程序附加:

  google.maps.event.addListener(marker,'click',function(){
//用这个标记做些什么...
this.setTitle('我被点击');
});

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


There's got to be a way to add a listener to ALL MARKERS, currently I'm adding a listener to each one using a loop which feels really wrong...

This feels wrong:

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

解决方案

In both Marker and MarkerWithLabel case, you might just as well use the this keyword to refer the object to which the event handler is attached:

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

this here is referring to the particular marker object.

这篇关于Google Maps API V3 - 将事件侦听器添加到所有标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆