如何在 Google Maps V3 上触发标记的 onclick 事件? [英] How to trigger the onclick event of a marker on a Google Maps V3?
本文介绍了如何在 Google Maps V3 上触发标记的 onclick 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从地图外部触发 Google 地图上标记的 onclick 事件?
How do I trigger the onclick event of a marker on a Google Maps from outside the map?
我使用 API 的版本 3.我看过很多版本 2 的教程,但找不到版本 3 的教程.
I use version 3 of the API. I've seen many tutorials for version 2, but can't find this for version 3.
我有一个全局数组(名为 markers),其中包含地图的所有标记 (google.maps.Marker).现在我想做一些类似的事情:
I have a global array (named markers) containing all the marker of the map (google.maps.Marker). Now I want do do something like:
markers[i].click(); //I know it's not working, but you get the idea...
//Next line seems to be the way in v2, but what's the equivalent in v3?
GEvent.trigger(markers[i], 'click');
感谢您的帮助,如果您需要更多信息,请告诉我!
Thanks for your help and if you need more info, let me know!
推荐答案
我找到了解决方案!感谢 Firebug ;)
I've found out the solution! Thanks to Firebug ;)
//"markers" is an array that I declared which contains all the marker of the map
//"i" is the index of the marker in the array that I want to trigger the OnClick event
//V2 version is:
GEvent.trigger(markers[i], 'click');
//V3 version is:
google.maps.event.trigger(markers[i], 'click');
这篇关于如何在 Google Maps V3 上触发标记的 onclick 事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文