Graticule can failover

acts_as_geocodable | geocoding | graticule September 12 2007

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.

posted by brandon | updated September 12th 08:38 PM
comments feed

4 comments

  1. 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. :-)

    Matt King Matt King
    September 15, 2007 at 12:22 PM
  2. Very nice.

    I’d love to see MapQuest added as a geocoding service

    Andrew Selder Andrew Selder
    October 19, 2007 at 03:13 PM
  3. 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.listings 

    but 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

    nathan nathan
    February 26, 2008 at 12:51 PM
  4. 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.

    Brandon Brandon
    March 03, 2008 at 11:08 PM

Speak your mind:

(Required)

(Required)


(You may use textile in your comments.)

About

I'm Brandon Keepers, a web application developer that likes beautiful code, valid markup and adherence to standards. As a part of Collective Idea in Holland, Michigan, I practice Agile software development primarily using Ruby on Rails.

-86.103171 42.785037

Contact:

more ยป

Syndicate