apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Drag and update location - how to do this? #465

Closed shayani closed 9 years ago

shayani commented 9 years ago

I'm trying to follow the information on your wiki, stackExchange, etc to make this work. The idea is to create a new location for the user. The app displays a map, put a marker on the 0,0 location and then the user drag this marker to any place and the form is updated with the new lat and log. Seems trivial and there's doc in the wiki, but I could not make it work.

I'm using gem version 2.1.2 and Rails 4.1. I had success showing maps, markers, etc, but I cannot make the callback and others functions to work. I'm using this doc to try: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Javascript-goodies#drop-a-marker-and-update-fields-attribute-in-a-form

Follow my view code:

handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
  markers = handler.addMarkers([
    {
      "lat": 0,
      "lng": 0,
    }
  ]
  );
  handler.bounds.extendWith(markers);
  handler.fitMapToBounds();
});

The rest of the javascript code is the same as the link provided before, but I'm replacing all "Gmaps.map" for "handler.getMap()"

Example:

Gmaps.map.callback = function() {...

becomes

handler.getMap().callback = function() {...

but nothing happens... not even an error :/

apneadiving commented 9 years ago

Hi,

please ask questions on stackoverflow, way easier for people to browse them afterwards.

Just quickly, there is no handler.getMap().callback.

Actually the callback is the second arg of the handler.buildMap function

shayani commented 9 years ago

Thanks. I tried to put the callback inside the second parameter. I also posted the question (still have doubts) in StackOverflow (http://stackoverflow.com/questions/27317767/drag-and-update-location-how-to-do-this)