Object
The Geocoder base class which defines the interface to be used by all other geocoders.
Call the geocoder service using the timeout if configured.
# File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 140
140: def self.call_geocoder_service(url)
141: Timeout::timeout(Geokit::Geocoders::request_timeout) { return self.do_get(url) } if Geokit::Geocoders::request_timeout
142: return self.do_get(url)
143: rescue TimeoutError
144: return nil
145: end
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.
# File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 150
150: def self.do_reverse_geocode(latlng)
151: return GeoLoc.new
152: end
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.
# File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 127
127: def self.geocode(address, options = {})
128: res = do_geocode(address, options)
129: return res.nil? ? GeoLoc.new : res
130: end
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.
# File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 134
134: def self.reverse_geocode(latlng)
135: res = do_reverse_geocode(latlng)
136: return res.success? ? res : GeoLoc.new
137: end
Wraps the geocoder call around a proxy if necessary.
# File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 163
163: def self.do_get(url)
164: uri = URI.parse(url)
165: req = Net::HTTP::Get.new(url)
166: req.basic_auth(uri.user, uri.password) if uri.userinfo
167: res = Net::HTTP::Proxy(GeoKit::Geocoders::proxy_addr,
168: GeoKit::Geocoders::proxy_port,
169: GeoKit::Geocoders::proxy_user,
170: GeoKit::Geocoders::proxy_pass).start(uri.host, uri.port) { |http| http.get(uri.path + "?" + uri.query) }
171: return res
172: end
Adds subclass’ geocode method making it conveniently available through the base class.
# File /Users/andre/projects/rails/geokit/lib/geokit/geocoders.rb, line 176
176: def self.inherited(clazz)
177: class_name = clazz.name.split('::').last
178: src = "def self.\#{Geokit::Inflector.underscore(class_name)}(address, options = {})\n\#{class_name}.geocode(address, options)\nend\n"
179: class_eval(src)
180: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.