Class: Geokit::Geocoders::Geocoder
- Inherits:
-
Object
- Object
- Geokit::Geocoders::Geocoder
- Defined in:
- lib/geokit/geocoders.rb,
lib/geokit/geocoders_v3.rb
Overview
The Geocoder base class which defines the interface to be used by all other geocoders.
Direct Known Subclasses
Class Method Summary collapse
-
.call_geocoder_service(url) ⇒ Object
Call the geocoder service using the timeout if configured.
-
.do_reverse_geocode(latlng) ⇒ Object
Not all geocoders can do reverse geocoding.
-
.geocode(address, options = {}) ⇒ Object
Main method which calls the do_geocode template method which subclasses are responsible for implementing.
-
.reverse_geocode(latlng) ⇒ Object
Main method which calls the do_reverse_geocode template method which subclasses are responsible for implementing.
Class Method Details
.call_geocoder_service(url) ⇒ Object
Call the geocoder service using the timeout if configured.
82 83 84 85 86 87 88 89 90 |
# File 'lib/geokit/geocoders.rb', line 82 def self.call_geocoder_service(url) Timeout::timeout(Geokit::Geocoders::request_timeout) { return self.do_get(url) } if Geokit::Geocoders::request_timeout logger.info "Getting geocode from #{url}" return self.do_get(url) rescue TimeoutError, Timeout::Error raise Geokit::TimeoutError rescue Yajl::HttpStream::HttpError raise Geokit::InvalidResponseError end |
.do_reverse_geocode(latlng) ⇒ Object
Not all geocoders can do reverse geocoding. So, unless the subclass explicitly overrides this method, a call to reverse_geocode will return an empty GeoLoc. If you happen to be using MultiGeocoder, this will cause it to failover to the next geocoder, which will hopefully be one which supports reverse geocoding.
95 96 97 |
# File 'lib/geokit/geocoders.rb', line 95 def self.do_reverse_geocode(latlng) return nil end |
.geocode(address, options = {}) ⇒ Object
Main method which calls the do_geocode template method which subclasses are responsible for implementing. Returns a populated GeoLoc or an nil one with a failed success code.
66 67 68 69 70 71 72 73 |
# File 'lib/geokit/geocoders.rb', line 66 def self.geocode(address, = {}) if address.is_a?(String) converted_address = ActiveSupport::Inflector.transliterate(address) else converted_address = address end do_geocode(converted_address, ) end |
.reverse_geocode(latlng) ⇒ Object
Main method which calls the do_reverse_geocode template method which subclasses are responsible for implementing. Returns a populated GeoLoc or an nil one with a failed success code.
77 78 79 |
# File 'lib/geokit/geocoders.rb', line 77 def self.reverse_geocode(latlng) do_reverse_geocode(latlng) end |