Geocoder
Geocoder Us geocoder implementation. Requires the Geokit::Geocoders::GEOCODER_US variable to contain true or false based upon whether authentication is to occur. Conforms to the interface set by the Geocoder class.
(Not documented)
# File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 249
249: def self.do_geocode(address, options = {})
250: address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address
251:
252: query = (address_str =~ /^\d{5}(?:-\d{4})?$/ ? "zip" : "address") + "=#{Geokit::Inflector::url_escape(address_str)}"
253: url = if GeoKit::Geocoders::geocoder_us
254: "http://#{GeoKit::Geocoders::geocoder_us}@geocoder.us/member/service/csv/geocode"
255: else
256: "http://geocoder.us/service/csv/geocode"
257: end
258:
259: url = "#{url}?#{query}"
260: res = self.call_geocoder_service(url)
261:
262: return GeoLoc.new if !res.is_a?(Net::HTTPSuccess)
263: data = res.body
264: logger.debug "Geocoder.us geocoding. Address: #{address}. Result: #{data}"
265: array = data.chomp.split(',')
266:
267: if array.length == 5
268: res=GeoLoc.new
269: res.lat,res.lng,res.city,res.state,res.zip=array
270: res.country_code='US'
271: res.success=true
272: return res
273: elsif array.length == 6
274: res=GeoLoc.new
275: res.lat,res.lng,res.street_address,res.city,res.state,res.zip=array
276: res.country_code='US'
277: res.success=true
278: return res
279: else
280: logger.info "geocoder.us was unable to geocode address: "+address
281: return GeoLoc.new
282: end
283: rescue
284: logger.error "Caught an error during geocoder.us geocoding call: "+$!
285: return GeoLoc.new
286:
287: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.