Geocoding webservice with Ruby and Perl
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”
=> [#
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.




