Google maps geocoding with rails

The past few days I have come back to some google maps fun geocoding in Rails 4 with gmaps4rails and geocoder

rails-google-maps

Direct geocoding with javascript in googlemaps

From javascript you can easily geocode an spot selected by the user by simply invoking the asynchronous geocoder.geocode() method as shown in the following code

Learn more about google maps for rails

Other users read also this article
Google maps rails crud sample application (I), creating a marker and saving its data in the database

Direct geocoding with gmaps4rails

The gmaps4rails gem adds a behaviour to allow to geocode your models based on a full address information that your model may contain. To achieve this you must add these gmaps4rails fields to your model and execute the migration.

The following code will add the latitude and longitude data to your model transparently

Inverse geocoding with geocoder

For those paranoids not trusting user input, the inverse geolocation by latitude and longitude is also available server-side with the geocoder gem. This is the code you need for that. Note: the extra fields latitud and longitude also apply here

You may want to review some source code for additional fields

Stay tuned for more maps fun!

 

Bytefilia