Method: Mapbox::Geocoder.assemble_params

Defined in:
lib/mapbox/geocoder.rb

.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(options={})
  proximity = options[:proximity]
  bbox = options[:bbox]
  types = options[:types]
  params = ''
  opts = options.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