Sep 26 2009

Geographical Data For Your Ruby on Rails Application

Ruby Rails Geodata Geonames | comments

Recently found some interesting gems that allow you to search postal codes via Geonames web service. In my case, I need more than just the country names, city names and region names. I need more relevant information like the currency code.

Ruby Geonames

Run the following if you haven't already:

              
              gem sources -a http://gems.github.com
              
              sudo gem install elecnix-ruby-geonames
              
              

Seems like a complex solution to a very simple problem. The most simple solution to load geonames data into a new database separate from your application. When you're running backups, you really don't need to backup data that hardly every changes so I think it's a good idea to have a separate database.

Espen shares how to import countries, regions and cities in no more than 2 minutes

In my case it took me 4 minutes to load the data due to a minor issue regarding syntax.

              LOAD DATA INFILE should be LOAD DATA LOCAL INFILE
              

6 megabytes of data migrated (2.5558s). Cool.

The data loaded does not have the full list of cities. But if you need the currency code (ISO 4217) of a country for instance that 2-minute solution is definitely for you.