geocoding info in Ruby.
Sometime last year, around the time of the 2007 RailsConf if I recall correctly, I wrote a tiny little gem called google-geo. It’s a simple group of classes for making queries against Google’s geocoding service and getting some classy objects in return.
Here are some choice examples from the README.
geo = Google::Geo.new API_KEY
addresses = geo.locate '1600 Amphitheatre Parkway, Mountain View, CA'
addresses.size # 1, :locate always returns an Array
address = addresses.first
address.country # 'US'
address.city # 'Mountain View'
address.full_address # '1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA'
address.query # '1600 Amphitheatre Parkway, Mountain View, CA'
address.accuracy # 8
In the case of sufficiently vague queries, Google::Geo will return more than one:
addresses = geo.locate 'hell'
addresses.size # 2
addresses.map { |a| a.state } # ['PA', 'NC']
Somebody recently contacted me about including this gem in a OpenBSD package, so I added in a LICENSE and put the project up on GitHub.
The “package” is just an OpenBSD application package. It would be similar to FreeBSD or NetBSD’s ports or Debian’s apt-get system. I’m using your Google-geo library in the web app I’m currently building. I found it very clean and helpful and though the rest of the OpenBSD community should know about it, so I’m creating an application package for it. Therefore, someone can just do a `pkg_add ruby-google-geo` and have your library installed. Also, if someone queries the OpenBSD packages looking for some kind of geo coding library, your library will pop up.
Very cool! Thanks, Clint.
I’ve always been pleased with this library. I think it’s a great example of simple quality.
- First, it has tests. The tests use fixtures based on reasonable assumptions about what we can expect from Google’s service. This means that you can run the tests anytime and very quickly.
- Second, it has no dependencies outside the standard Ruby libraries. XML parsing is relegated to a couple simple methods that use regular expressions to extract values from the response markup. Heresy, eh? No, quality. The overhead and complexity of a “real” parsing library is simply. not. needed.
- Aaannnd you get great objects to work with.
Score!



[...] by Rlewis580 on Tue 23-12-2008 July 2008 stats report Saved by nickyboston on Mon 15-12-2008 geocoding info in Ruby. Saved by JetPlane on Mon 15-12-2008 Geocoding postcodes Saved by ismyfacedirty on Mon 08-12-2008 [...]