Class: Mapbox::Geocoder
- Inherits:
-
Object
- Object
- Mapbox::Geocoder
- Extended by:
- HashUtils
- Includes:
- APIOperations::Request
- Defined in:
- lib/mapbox/geocoder.rb
Class Method Summary collapse
- .geocode_forward(query, options = {}, dataset = 'mapbox.places') ⇒ Object
- .geocode_reverse(location, dataset = 'mapbox.places') ⇒ Object
Methods included from HashUtils
Methods included from APIOperations::Request
Class Method Details
.geocode_forward(query, options = {}, dataset = 'mapbox.places') ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mapbox/geocoder.rb', line 10 def self.geocode_forward(query, ={}, dataset='mapbox.places') proximity = [:proximity] bbox = [:bbox] params = '' opts = .select { |key, value| key != :proximity && key != :bbox} 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 return request( :get, "/geocoding/v5/#{dataset}/#{URI.escape(query)}.json#{params}", nil) end |
.geocode_reverse(location, dataset = 'mapbox.places') ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/mapbox/geocoder.rb', line 34 def self.geocode_reverse(location, dataset='mapbox.places') location[:longitude] = location[:longitude].round(5) location[:latitude] = location[:latitude].round(5) return request( :get, "/geocoding/v5/#{dataset}/#{xy_from_hash(location).join(',')}.json", nil) end |