我有这个工作代码:
google.maps.event.addListener(marker, 'click', (function (marker, i)
{
return function ()
{
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
但是,我想把它改成 jQuery。
我试过了,但没有成功。
$(google.maps.event).on('click', marker, function ()
{
(function (marker, i)
{
return function ()
{
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i)
});
有什么帮助吗?
最佳答案
您试图将 google.maps.event
视为 DOM 元素,但事实并非如此。 .addListener
是 Google Maps API 独有的方法,不能由 jQuery 控制。
但是,有几个 jQuery 插件旨在简化对 Google Maps API 的操作。我自己最近用过gMap 2取得了巨大的成功。 Google 搜索“jquery plugin google maps”将返回许多类似的插件,包括 one of Google's own .
关于javascript - 将 google map v3 点击事件更改为 jquery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11580915/