使用Google Maps for Rails删除图钉

时间:2013-12-05 01:09:30

标签: ruby-on-rails ruby-on-rails-3 google-maps google-maps-api-3 gmaps4rails

我目前正在使用Google Maps for Rails来显示从数据库中的某些地理编码数据生成的一些标记,并且效果很好:)现在我想添加功能并允许用户删除引脚(标记)地图,并最终将这些坐标记录到数据库中(我想通过一个安静的电话)。但是现在我试图了解是否/如何将google.maps.event.addListener配置为buildMap。我当前的buildMap到漂亮的盒子标准:

handler = Gmaps.build('Google');
    handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
      markers = handler.addMarkers(<%=raw @hash.to_json %>);
      handler.map.centerOn({ lat: 51.5008, lng: 0.1247 }) //center on Big ben
      handler.bounds.extendWith(markers);
      handler.fitMapToBounds();
    });

任何帮助都会参与其中:)

1 个答案:

答案 0 :(得分:3)

在回调中添加侦听器:

handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
  markers = handler.addMarkers(<%=raw @hash.to_json %>);
  handler.map.centerOn({ lat: 51.5008, lng: 0.1247 }) //center on Big ben
  handler.bounds.extendWith(markers);
  handler.fitMapToBounds();

  google.maps.event.addListener(handler.getMap(), 'click', yourFunction)
});