Google adds more countries to geocoder
Google has added support for India, Hong Kong, Taiwan, Singapore, and Ireland to their geocoder. If you’re using Graticule, it should Just Work™. Let me know if you have any problems.
Is this your first visit? You may want to subscribe to the feed.
Graticule has a new geocoder that simply calls other geocoders in succession until it gets a result.
geocoder = Graticule.service(:multi).new(
Graticule.service(:google).new("api_key"),
Graticule.service(:yahoo).new("api_key"),
)
geocoder.locate '49423' # <= tries geocoders in succession
This can also be used in acts_as_geocodable by simply setting Geocode.geocoder to the new multi-geocoder. See the API docs for more information.
Thanks to Matt King for some ideas on the implementation and Ben Tucker for nudging me to implement it.
Google has added support for India, Hong Kong, Taiwan, Singapore, and Ireland to their geocoder. If you’re using Graticule, it should Just Work™. Let me know if you have any problems.
Good news for the Brits: UK Geocoding Now Available in the Maps API. This means that the Google geocoder in Graticule should now work in the UK. I’m interested to hear how well it works from anyone using it.
Three Graticule related updates:
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]
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.
I’m just an ignorant North-American, so I would love some feedback from people using Graticule and acts_as_geocodable outside the US.
3?, nope there is no 3. Geocoding as easy as 1-2!
event = Event.create :street => "777 NE Martin Luther King, Jr. Blvd.",
:city => "Portland", :region => "Oregon", :postal_code => 97232
# how far am I from RailsConf 2007?
event.distance_to "49423" #=> 1807.66560483205
# Find our new event, and any other ones in the area
Event.find(:all, :within => 50, :origin => "97232")
# Find the nearest restaurant with beer
Restaurant.find(:nearest, :origin => event, :conditions => 'beer = true')
I know you’re excited, so instead of blabbing on-and-on, FAQ-style:
A slick new plugin called acts_as_geocodable.
script/plugin install -x git://github.com/collectiveidea/acts_as_geocodable.git
Its all in the README.
The Ruby geocoding space is pretty fragmented right now. There’s all kinds of geocoders available, and none of them provide everything. We’re determined to fix that with Graticule and acts_as_geocodable.
We believe that all the heavy lifting of geocoding, distance calculations, etc., should be left to a gem, and only code that is directly related to Rails should be a Rails plugin. Even more, all the different geocoders should be available in the same package and have the same interface. A plugin should then be built on top of the gem that makes your apps geo-capabilities seem like voodoo.
We started our own projects because we didn’t think anyone else got it right. Recently, Bill Eisenhaur and Andre Lewis did a pretty good job, and we borrowed some of their ideas, but I still have issues with their approach and code, mainly that it’s all tied up into a Rails plugin.
I think we have a great foundation. It’s not perfect, nor does it have all the features of the other packages, but I think it is well architected.
Excellent idea! We would love to.
(Why are you asking this?) A third of the problem is knowing where, a third is when, and a third is who. You’re on your own for the who and when.
Happy geocoding!
update: Graticule is now hosted on Rubyforge.
Graticule is a geocoding API for interpolating address data into geographic coordinates written in Ruby. The goal is to provide a consistent interface into the various geocoding services, allowing other libraries to be built on top of them while remaining agnostic of the specific service that is being used.
In its current state, Graticule is just a repackaging of the different gems produced by Eric Hodel of Robot Co-op. It currently supports the Yahoo, Google, Geocoder.us, and MetaCarta APIs. The plan is to expand upon them.
You can grab the gem or check out the code from Subversion. The Rdoc is also available.
require 'rubygems'
require 'graticule'
geocoder = Graticule.service(:google).new "api_key"
location = geocoder.locate "1600 Amphitheatre Parkway, Mountain View, CA"
I’d love to get your feedback. There are a few places where the API is still not consistent (e.g. Yahoo returns multiple results). I’d also appreciate any help with packaging and releasing as I am a newbie at creating Gems.