Graticule can failover
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.








4 comments
This is awesome! I’ll be updating the gem and trying it out on my development box. I was going to mention adding in precision checking but I see that’s already in there. :-)
September 15, 2007 at 12:22 PM
Very nice.
I’d love to see MapQuest added as a geocoding service
October 19, 2007 at 03:13 PM
Ok so i modified Graticule gem by adding a new geocoder(http://plasmicpeach.com/articles/2007/09/12/uk-geocoding-with-google-and-graticule) so i can use UK google service. acts_as_geocode works fine with it but i’m trying to find a way to utilise :include with :origin and :order => distance. Duplex on railsforum suggested
location = Location.find :all, :origin => postal_code, :order => "distance asc", :include => :listings, #eager-loading for performance :conditions => "state = 'published'" list = location.listingsbut it cuases SQL errors about distance.
anyone got any ideas?
great plugin but unless i can find someway of using it with has_many belongs_to relationships then it’s not going to be suitable for my project.
cheers Nathan
February 26, 2008 at 12:51 PM
nathan:
This is actually a limitation in ActiveRecord with using :select (which graticule uses to perform distance calculations) and :include in a find. I believe there are some workarounds somewhere, but I haven’t looked into them.
March 03, 2008 at 11:08 PM
Speak your mind: