Class: CloudMade::GeocodingService
- Defined in:
- lib/cloudmade/geocoding.rb
Overview
Class that is responsible for geocoding services of Cloudmade
Instance Attribute Summary
Attributes inherited from Service
Instance Method Summary collapse
-
#find(query, options = {}) ⇒ Object
Find objects that match given query.
-
#find_closest(object_type, lat, lon, options = {}) ⇒ Object
TODO: Modify lat, lon parameters to point.
-
#url_template ⇒ Object
:nodoc:.
Methods inherited from Service
Instance Method Details
#find(query, options = {}) ⇒ Object
Find objects that match given query. Returns GeoResults object.
-
query
Query by which objects should be searched -
options
Additional options, contains
results: How many results should be returned. skip: Number of results to skip from beginning. bbox: Bounding box in which objects should be searched. bbox_only: If set to False, results will be searched in the whole world if there are no results for a given bbox. return_geometry: If specified, adds geometry in returned results. Defaults to true.
33 34 35 36 37 38 39 40 41 |
# File 'lib/cloudmade/geocoding.rb', line 33 def find(query, = {}) ['results'] = 10 unless .has_key? 'results' ['skip'] = 0 unless .has_key? 'skip' ['bbox_only'] = true unless .has_key? 'bbox_only' ['return_geometry'] = true unless .has_key? 'return_geometry' request = "/find/#{CGI.escape(query)}.js?#{Service.to_url_params()}" GeoResults.new(JSON.parse(connect request)) end |
#find_closest(object_type, lat, lon, options = {}) ⇒ Object
TODO: Modify lat, lon parameters to point
55 56 57 58 59 60 61 |
# File 'lib/cloudmade/geocoding.rb', line 55 def find_closest(object_type, lat, lon, = {}) lat_lon = "#{CGI.escape(lat.to_s + '+' + lon.to_s)}" request = "/closest/#{object_type}/#{lat_lon}.js?#{Service.to_url_params()}" geo_results = GeoResults.new(JSON.parse(connect request)) raise ObjectNotFound.new if (geo_results.results == nil or geo_results.results.size == 0) return geo_results.results[0] end |
#url_template ⇒ Object
:nodoc:
64 65 66 |
# File 'lib/cloudmade/geocoding.rb', line 64 def url_template return "http://#{@subdomain}.#{@connection.url}/#{@connection.api_key}/geocoding" end |