Вопрос

I'm currently using Google Maps for Rails to display some markers generated from some geocoded data in a database and that works great :) Now I'd like to add functionality and allow users to drop a pin (marker) on the map and eventually have those co-ordinates recorded to the database (via a restful call I guess). But for now I'm trying to understand if/how I'd configure a google.maps.event.addListener to buildMap. My current buildMap to pretty box standard:

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();
    });

Any help would be much participated :)

Это было полезно?

Решение

add the listener in the callback:

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)
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top