Sha256: 78cabbc02d04d5f5024d76aaaa4885e8832f09177939898fe56336334248004e
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
# 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: # <?xml version="1.0" encoding="UTF-8" ?> # <geodata> # <latt>49.243086</latt> # <longt>-123.153684</longt> # </geodata> module Geokit module Geocoders class CaGeocoder < Geocoder config :key private # Template method which does the geocode lookup. def self.do_geocode(loc) process :xml, submit_url(loc), GeoLoc.new end def self.parse_xml(xml, loc) loc.lat = xml.elements["//latt"].text loc.lng = xml.elements["//longt"].text loc.city = xml.elements["//city"].text loc.street_number = xml.elements["//stnumber"].text loc.street_address = xml.elements["//staddress"].text loc.state = xml.elements["//prov"].text loc.province = xml.elements["//prov"].text loc.zip = xml.elements["//postal"].text loc.success = true loc end # Formats the request in the format acceptable by the CA geocoder. def self.submit_url(loc) args = ["locate=#{Geokit::Inflector.url_escape(loc)}"] args << "auth=#{key}" if key args << "geoit=xml" "http://geocoder.ca/?" + args.join("&") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
geokit-1.10.0 | lib/geokit/geocoders/ca_geocoder.rb |