I am using rails 3.2.3 and gmaps4rails gem.
I have one model called contact. In the contact object I have one filed named address.
Now I have defined the contact as acts_as_gmappable and gmaps4rails_address takes the address field to show as a marker in the google map.
Now, while we add new contact, I want to add a feature such that the address will be auto filled when we click on the google map with the clicked location.
How can I do that with the help of gmaps4rails gem?
There is a good guide on the wiki that might help. Look for the section “Drop a marker and update fields attribute in a form”
https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Javascript-goodies
Simply include the javascript, and update the following with your actual field IDs (you might want some hidden :lat :lon fields on your form)
On save, you’ll need to check whether the user has entered an address manually, or used the map.
If they’ve used the map, you’ll need a method to reverse geocode and fetch an address from Google using the :lat :lon values.