Rails – Find Location using Geocoder

Geocoder is a Rails Gem which helps you to manipulate location in your Rails application. It is written by Alex Reisner. Thanks for his work and you can find out more details at Github – alexreisner / geocoder.

Let’s try it now.

1. Add the Geocoder Gem in your application by adding the following line in the Gemfile

  • gem ‘geocoder’

 

2. Run bundle install to install the newly added Gem

3. Start the Rails console and you can try the Geocoder functions

  • Geocoder.coordinates(“Hong Kong”)
  • Geocoder.search(“Hong Kong”)


 

The above coordinates are provided by Google which is the default Geocoding API. You can switch to other services by editing the config/initializers/geocoder.rb.

Geocoder::Configuration.lookup = :google
#Geocoder::Configuration.lookup = :yahoo
#Geocoder::Configuration.lookup = :geocoder_ca

 

You can also integrate the Geocoder with models. I will spend some times on it later.

Done =)

Reference: Github – alexreisner / geocoder

One thought on “Rails – Find Location using Geocoder”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.