Geocoding webservice with Ruby and Perl

Posted by Scott on January 13, 2007

A year or so ago I was trying out the Google Maps API. At the time, Google did not provide a means to geocode your own locations (although now they do), so I set out to create my own geocoder. There was a good overview on how to create your own database of locations based on the Census Bureau’s TIGER/line data. I took quite awhile to download all the data and then construct the berkley database (about 1gb in size), but in the end it worked great. Next, I made use of the Geo::Coder::US Perl module, wrote a Perl web service and created my Rails app to pull everthing together.

Anyway, I finally sat down to blog about what I did (a year ago) and, of course, some other folks beat me to it. There’s also a pretty cool Ruby geocoder Gem that I’ve just been playing with. It uses the the geocoding webservices provided by Yahoo and geocoder.us. Of course, their are limits on these: the Yahoo service is limited to 5,000 requests per day and the geocoder.us service is for non-commercial use only. In any case, either should acceptable for many purposes. It would be nice if support is added for the Google service, which allows 50,000 request per day. I’ll probably keep my service around, but will likely switch to the gem version so I can let Yahoo worry about keeping the database up-to-date.

Here’s a basic example using the gem version in irb:
[ruby]
>> require ‘geocoder’
==> true
>> geocoder = Geocoder::Yahoo.new “my_yahoo_app_id”
=> #
>> result =
geocoder.geocode “1600 pennsylvania ave nw washington dc”
=> [# longitude="-77.037223", address="1600 PENNSYLVANIA AVE NW",
city="WASHINGTON", state="DC", zip="20500-0003",
country="US", precision="address", warning=nil>]
>> result.lat
=> “38.898563″
>> result.lng
=> “-77.037223″
[/ruby]

That’s all that’s needed. You can be getting your own coordinates in minutes.

Leave a Reply

Who Are These Guys?

Netphase, LLC. is a Charlotte-based web application development company specializing in really rapid application development on the Ruby on Rails framework.

Netphase was founded by Scott Nedderman and Chris Beck in 2007. Both Scott and Chris have been active Ruby on Rails developers for more than 3 years, and each has spent more than a decade designing, devloping and deploying web applications.

We have worked on projects of all sizes, and delivered successful sites to production for some of the biggest names in the business. For all of the gory details, check out our about page.

Bookmark This

del.icio.us Digg Furl reddit