javascript - 将 google map v3 点击事件更改为 jquery?

标签 javascript jquery google-maps google-maps-api-3

我有这个工作代码:

 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/

相关文章:

jquery - 在 jquery 中重新加载函数或 var(新手)

javascript - Math.max() 用于变量

javascript - 在 JavaScript 中安全地定义公共(public)回调函数的变量

jQuery CSS 选择器问题

javascript - Ajax 在循环中成功设置全局变量

google-maps - Google Maps Embed 无法在 IE 上运行

javascript - JS/jQuery(隐藏div,点击显示div)

javascript - 如何使用 javaScript 在运行时设置 HTML 属性值?

java - 如何在android中的谷歌地图的特定半径内绘制标记

android - 使用 Google Play 服务中的设置 API 启用 "High Accuracy"位置