Class: Mapbox::Geocoder
- Inherits:
-
Object
- Object
- Mapbox::Geocoder
- Extended by:
- HashUtils
- Includes:
- APIOperations::Request
- Defined in:
- lib/mapbox/geocoder.rb
Class Method Summary collapse
- .assemble_params(options = {}) ⇒ Object
- .geocode_forward(query, options = {}, dataset = 'mapbox.places') ⇒ Object
- .geocode_reverse(location, options = {}, dataset = 'mapbox.places') ⇒ Object
Methods included from HashUtils
Methods included from APIOperations::Request
Class Method Details
.assemble_params(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mapbox/geocoder.rb', line 10 def self.assemble_params(={}) proximity = [:proximity] bbox = [:bbox] types = [:types] params = '' opts = .select { |key, value| key != :proximity && key != :bbox && key != :types} if opts.length > 0 params += "#{params.length > 0 ? '&' : '?'}#{URI.encode_www_form(opts)}" end if proximity then lon = proximity[:longitude].round(3) lat = proximity[:latitude].round(3) params += "#{params.length > 0 ? '&' : '?'}proximity=#{lon}%2C#{lat}" end if bbox then params += "#{params.length > 0 ? '&' : '?'}bbox=#{bbox.join('%2C')}" end if types then params += "#{params.length > 0 ? '&' : '?'}types=#{types.join('%2C')}" end return params end |
.geocode_forward(query, options = {}, dataset = 'mapbox.places') ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/mapbox/geocoder.rb', line 37 def self.geocode_forward(query, ={}, dataset='mapbox.places') params = self.assemble_params() return request( :get, "/geocoding/v5/#{dataset}/#{URI.encode_www_form_component(query)}.json#{params}", nil) end |
.geocode_reverse(location, options = {}, dataset = 'mapbox.places') ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mapbox/geocoder.rb', line 46 def self.geocode_reverse(location, ={}, dataset='mapbox.places') location[:longitude] = location[:longitude].round(5) location[:latitude] = location[:latitude].round(5) params = self.assemble_params() return request( :get, "/geocoding/v5/#{dataset}/#{xy_from_hash(location).join(',')}.json#{params}", nil) end |