opensoul.org

Graticule and acts_as_geocodable go international

March 27, 2007 code 3 min read

The single biggest request that I’ve gotten for Graticule and acts_as_geocodable has been for international support. So, for those outside the US (50% that read this blog according to google analytics), I have a present for you.

Last weekend I committed support for Local Search Maps (thanks to James Stewart), and PostcodeAnywhere, both of which have some international support, at least for Canada and Europe. I also added geocoder.ca.

Most of the international geocoding services seem to require a little more structured parameters, so with Graticule 0.2, all of the geocoders can take a hash (and some require it). As a result of gaining international support, the field names that Graticule uses have been changed to be more international-friendly: street, locality, region, postal_code, and country.

g = Graticule.service(:local_search_maps).new
location = g.locate :street => '48 Leicester Square', :locality => 'London', :country => 'UK'
location.coordinates  #=> [51.510036, -0.130427]

Geocoding IP Addresses

Several people mentioned that they would rather use acts_as_geocodable, but chose to use GeoKit, another good geocoding library (but with a little different philosophy), because it had support for geocoding IP addresses. So, with a flick of the wrist and a twitch of the nose, Graticule now supports HostIP for geocoding IP addresses:

g = Graitucle.service(:host_ip).new
location = g.locate "64.233.167.99"

location.coordinates  #=> [37.402, -122.078]
location.locality     #=> "Mountain View"
location.country      #=> "US"
location.region       #=> "CA"

Along with this, acts_as_geocodable has a helper method, remote\_location:

@nearest_store = Store.find(:nearest, :origin => remote_location) if remote_location

Be careful not to rely too heavily on remote_location because the location of many IP addresses cannot be determined through HostIP.

Feedback

I’m just an ignorant North-American, so I would love some feedback from people using Graticule and acts_as_geocodable outside the US.

This content is open source. Suggest Improvements.

@bkeepers

avatar of Brandon Keepers I am Brandon Keepers, and I work at GitHub on making Open Source more approachable, effective, and ubiquitous. I tend to think like an engineer, work like an artist, dream like an astronaut, love like a human, and sleep like a baby.