Is this your first visit? You may want to subscribe to the feed.

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.

Code: acts_as_geocodable, geocoding, graticule Sep 12, 2007 ● updated Sep 12, 2007 5 comments

5 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
  5. Hi Brandon, just want to say how great acts_as_geocodable and graticule are – the source has more or less taught me geocoding, which is just fantastic, so sincerely thank you.

    I understand from the acts_as_geocodable page that contributions are welcome, so I’m making some minor changes I’m using on a project.

    These changes will be on github in case they are of use to anyone else (at time of writing I’ve not committed these): http://github.com/eliotsykes/acts_as_geocodable_extra/tree/master

    Eliot Eliot October 29, 2008 at 04:00 PM

Speak your mind:

*

*


* I hate spam and will never sell or publish your email address.

(You may use textile in your comments.)

Subscribe

Browse by Tag