Parent

Methods

Geokit::Geocoders::YahooGeocoder

Yahoo geocoder implementation. Requires the Geokit::Geocoders::YAHOO variable to contain a Yahoo API key. Conforms to the interface set by the Geocoder class.

Private Class Methods

do_geocode(address, options = {}) click to toggle source

Template method which does the geocode lookup.

     # File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 297
297:       def self.do_geocode(address, options = {})
298:         address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address
299:         url="http://api.local.yahoo.com/MapsService/V1/geocode?appid=#{Geokit::Geocoders::yahoo}&location=#{Geokit::Inflector::url_escape(address_str)}"
300:         res = self.call_geocoder_service(url)
301:         return GeoLoc.new if !res.is_a?(Net::HTTPSuccess)
302:         xml = res.body
303:         doc = REXML::Document.new(xml)
304:         logger.debug "Yahoo geocoding. Address: #{address}. Result: #{xml}"
305: 
306:         if doc.elements['//ResultSet']
307:           res=GeoLoc.new
308: 
309:           #basic      
310:           res.lat=doc.elements['//Latitude'].text
311:           res.lng=doc.elements['//Longitude'].text
312:           res.country_code=doc.elements['//Country'].text
313:           res.provider='yahoo'  
314: 
315:           #extended - false if not available
316:           res.city=doc.elements['//City'].text if doc.elements['//City'] && doc.elements['//City'].text != nil
317:           res.state=doc.elements['//State'].text if doc.elements['//State'] && doc.elements['//State'].text != nil
318:           res.zip=doc.elements['//Zip'].text if doc.elements['//Zip'] && doc.elements['//Zip'].text != nil
319:           res.street_address=doc.elements['//Address'].text if doc.elements['//Address'] && doc.elements['//Address'].text != nil
320:           res.precision=doc.elements['//Result'].attributes['precision'] if doc.elements['//Result']
321:           # set the accuracy as google does (added by Andruby)
322:           res.accuracy=%w{unknown country state state city zip zip+4 street address building}.index(res.precision)
323:           res.success=true
324:           return res
325:         else 
326:           logger.info "Yahoo was unable to geocode address: "+address
327:           return GeoLoc.new
328:         end   
329: 
330:         rescue 
331:           logger.info "Caught an error during Yahoo geocoding call: "+$!
332:           return GeoLoc.new
333:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.