Class: Geocoder::Lookup::AmazonLocationService

Inherits:
Base
  • Object
show all
Defined in:
lib/geocoder/lookups/amazon_location_service.rb

Instance Method Summary collapse

Methods inherited from Base

#cache, #handle, #initialize, #map_link_url, #name, #query_url, #required_api_key_parts, #search, #supported_protocols

Constructor Details

This class inherits a constructor from Geocoder::Lookup::Base

Instance Method Details

#results(query) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/geocoder/lookups/amazon_location_service.rb', line 6

def results(query)
  params = query.options.dup

  # index_name is required
  # Aws::ParamValidator raises ArgumentError on missing required keys
  params.merge!(index_name: configuration[:index_name])

  # Aws::ParamValidator raises ArgumentError on unexpected keys
  params.delete(:lookup)

  # Inherit language from configuration
  params.merge!(language: configuration[:language])

  resp = if query.reverse_geocode?
    client.search_place_index_for_position(params.merge(position: query.coordinates.reverse))
  else
    client.search_place_index_for_text(params.merge(text: query.text))
  end

  resp.results
end