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.
5 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. :-)
Very nice.
I’d love to see MapQuest added as a geocoding service
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
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.
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
Speak your mind: