【问题标题】:Google maps for Rails: after map load callbackRails 的谷歌地图:地图加载回调后
【发布时间】:2015-08-11 02:21:17
【问题描述】:

如何在 Gmaps for Rails 的信息窗口中添加回调函数?我需要为该窗口中的按钮 inside 编写 Ajax/JSON 函数。

搜索并没有让我走得太远。有什么帮助吗?

<script type='text/javascript'>
  handler = Gmaps.build('Google');
  handler.buildMap({
    provider: {
      mapTypeId: google.maps.MapTypeId.SATELLITE
    },
    internal: { id: 'map' }
  },
  function(){
    markers = handler.addMarkers(<%= raw @map_hash.to_json %>);
    handler.bounds.extendWith(markers);
    handler.fitMapToBounds();
    // trying to add this function
    google.maps.event.addListenerOnce(handler.map, 'idle', function() {
    console.log('map loaded');
    $('.survey-response').click(function() {
      var id = $(this).attr('data-id');
      var response = $(this).attr('data-response');
      console.log(id + ' ' + response);
      $.getJSON('/potentials/' + id + '/' + response, function (data) {
        console.log(data);
      })
    })
  })
  });
</script>

从上面删除回调(在注释之后)并使用此代码:

google.maps.event.addListener(Gmaps.map, "click", function() {
  alert("You clicked the map.");
});

返回此错误:

Cannot read property '__e3_' of undefined

谢谢。

【问题讨论】:

    标签: javascript ruby-on-rails google-maps ruby-on-rails-4 gmaps4rails


    【解决方案1】:

    您应该创建自己的构建器来处理信息窗口as explained there

    这样你就可以根据需要绑定你的js事件了。

    【讨论】:

      猜你喜欢
      • 2018-06-16
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      • 2020-02-12
      • 1970-01-01
      相关资源
      最近更新 更多