Class: Geokit::Geocoders::Geocoder

Inherits:
Object
  • Object
show all
Defined in:
lib/geokit/geocoders/geocoder.rb

Overview

The Geocoder base class which defines the interface to be used by all other geocoders.

Class Method Summary collapse

Class Method Details

.call_geocoder_service(url) ⇒ Object

Call the geocoder service using the timeout if configured.



28
29
30
31
32
33
# File 'lib/geokit/geocoders/geocoder.rb', line 28

def self.call_geocoder_service(url)
  Timeout::timeout(Geokit::Geocoders::request_timeout) { return self.do_get(url) } if Geokit::Geocoders::request_timeout
  return self.do_get(url)
rescue TimeoutError
  return nil
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.



38
39
40
# File 'lib/geokit/geocoders/geocoder.rb', line 38

def self.do_reverse_geocode(latlng)
  return GeoLoc.new
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 empty one with a failed success code.



15
16
17
18
# File 'lib/geokit/geocoders/geocoder.rb', line 15

def self.geocode(address, options = {})
  res = do_geocode(address, options)
  return res.nil? ? GeoLoc.new : res
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 empty one with a failed success code.



22
23
24
25
# File 'lib/geokit/geocoders/geocoder.rb', line 22

def self.reverse_geocode(latlng)
  res = do_reverse_geocode(latlng)
  return res.success? ? res : GeoLoc.new
end