Parent

Geokit::Geocoders::CaGeocoder

Geocoder CA geocoder implementation. Requires the Geokit::Geocoders::GEOCODER_CA variable to contain true or false based upon whether authentication is to occur. Conforms to the interface set by the Geocoder class.

Returns a response like:

  <latt>49.243086</latt>
  <longt>-123.153684</longt>

Private Class Methods

add_ampersand(url) click to toggle source

(Not documented)

     # File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 238
238:       def self.add_ampersand(url)
239:         url && url.length > 0 ? "&" : ""
240:       end
construct_request(location) click to toggle source

Formats the request in the format acceptable by the CA geocoder.

     # File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 226
226:       def self.construct_request(location)
227:         url = ""
228:         url += add_ampersand(url) + "stno=#{location.street_number}" if location.street_address
229:         url += add_ampersand(url) + "addresst=#{Geokit::Inflector::url_escape(location.street_name)}" if location.street_address
230:         url += add_ampersand(url) + "city=#{Geokit::Inflector::url_escape(location.city)}" if location.city
231:         url += add_ampersand(url) + "prov=#{location.state}" if location.state
232:         url += add_ampersand(url) + "postal=#{location.zip}" if location.zip
233:         url += add_ampersand(url) + "auth=#{Geokit::Geocoders::geocoder_ca}" if Geokit::Geocoders::geocoder_ca
234:         url += add_ampersand(url) + "geoit=xml"
235:         'http://geocoder.ca/?' + url
236:       end
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 207
207:       def self.do_geocode(address, options = {})
208:         raise ArgumentError('Geocoder.ca requires a GeoLoc argument') unless address.is_a?(GeoLoc)
209:         url = construct_request(address)
210:         res = self.call_geocoder_service(url)
211:         return GeoLoc.new if !res.is_a?(Net::HTTPSuccess)
212:         xml = res.body
213:         logger.debug "Geocoder.ca geocoding. Address: #{address}. Result: #{xml}"
214:         # Parse the document.
215:         doc = REXML::Document.new(xml)    
216:         address.lat = doc.elements['//latt'].text
217:         address.lng = doc.elements['//longt'].text
218:         address.success = true
219:         return address
220:       rescue
221:         logger.error "Caught an error during Geocoder.ca geocoding call: "+$!
222:         return GeoLoc.new  
223:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.