Class: Geokit::Geocoders::HereGeocoder
- Inherits:
-
Geocoder
- Object
- Geocoder
- Geokit::Geocoders::HereGeocoder
- Defined in:
- lib/geokit_here_geocoder.rb
Class Method Summary collapse
- .api_endpoint ⇒ Object
- .do_geocode(address, options = {}) ⇒ Object
- .parse_xml(xml) ⇒ Object
- .submit_url(address) ⇒ Object
Class Method Details
.api_endpoint ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/geokit_here_geocoder.rb', line 36 def self.api_endpoint if ENV['RAKE_ENV'] == 'test' "https://geocoder.cit.api.here.com/6.2/geocode.xml" else "https://geocoder.api.here.com/6.2/geocode.xml" end end |
.do_geocode(address, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/geokit_here_geocoder.rb', line 12 def self.do_geocode(address, = {}) if (app_id.nil? || app_id.empty?) || (app_code.nil? || app_code.empty?) raise(Geokit::Geocoders::GeocodeError, "Here geocoder API requires auth id and code to use their service.") end process :xml, submit_url(address) end |
.parse_xml(xml) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/geokit_here_geocoder.rb', line 58 def self.parse_xml(xml) results = xml.elements.to_a("//Result") return GeoLoc.new if results.nil? || results.count == 0 loc = new_loc # only take the first result set_mappings(loc, results.first, XML_MAPPINGS) loc.success = true loc end |
.submit_url(address) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/geokit_here_geocoder.rb', line 21 def self.submit_url(address) args = [] args << ["app_id", app_id] args << ["app_code", app_code] args << ["additionaldata", "Country2,1"] args << ["language", "en-US"] args << ["gen", "9"] address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address args << ["searchtext", address_str] [api_endpoint, '?', URI.encode_www_form(args)].join('') end |