【问题标题】:Problem with event listener in google maps (with fusion tables)谷歌地图中的事件监听器问题(带有融合表)
【发布时间】:2011-10-18 18:35:15
【问题描述】:

我正在尝试在 jquery 移动应用程序中使用谷歌地图。地图有一个融合表图层,图层加载正常,点击监听器被调用,但给回调函数的值为空。我需要使用与单击的标记关联的值。

设置图层并添加事件监听器。

var layer = new google.maps.FusionTablesLayer({
     query: {
         select: 'Address',
         from: table_id
     }
});

// map is an instance of google.maps.Map
layer.setMap(map)

google.maps.event.addListener(layer, 'click', function(e) {
     console.log(e);
     $.mobile.changePage(...);
});

我是否正确使用了 addListener?

相关documentation

相关example

【问题讨论】:

  • 是的,我是。 console.log(e) 打印 'null' 和任何引用“应该”在 e 中的值的尝试 (e.row['Address'].value) 给出“无法读取 null 的属性 'row'” .
  • 代码正常工作。 A 出于其他原因重新启动了我的计算机,并且代码现在可以工作了。

标签: javascript google-maps-api-3 google-fusion-tables


【解决方案1】:

在我允许 Fusion Table Layer 显示信息窗口之前,我遇到了类似的问题,

layer = new google.maps.FusionTablesLayer({
    query: {
      select: 'location',
      from: tableid
    },
//    options: {suppressInfoWindows: true}, // don't suppress or you lose the event 
    map: map
  }

希望这会有所帮助。

【讨论】:

  • 我认为即使你使用 {suppressInfoWindows: true} 它应该可以工作,但在删除浏览器缓存之后。
【解决方案2】:

代码正常工作。重新启动我的计算机,问题似乎已经消失。 (也许是清除缓存?)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多