diff --git a/lib/geocoder/lookups/pelias.rb b/lib/geocoder/lookups/pelias.rb index 31c89696881a85a679e5f96b2a41b8221a1affa6..225462550d4eb70abf4430c942c787b3a3ea089a 100644 --- a/lib/geocoder/lookups/pelias.rb +++ b/lib/geocoder/lookups/pelias.rb @@ -23,11 +23,19 @@ module Geocoder::Lookup private def query_url_params(query) - { + params = { api_key: configuration.api_key, - text: query.text, size: 1 - }.merge(super(query)) + }.merge(super) + + if query.reverse_geocode? + lat,lon = query.coordinates + params[:'point.lat'] = lat + params[:'point.lon'] = lon + else + params[:text] = query.text + end + params end def results(query) diff --git a/test/unit/lookups/pelias_test.rb b/test/unit/lookups/pelias_test.rb index ba209d6e1d379946b9bafde5ac281fcd96007687..2482646273c6b90e29aec59ebeb1a03ecc9f74ac 100644 --- a/test/unit/lookups/pelias_test.rb +++ b/test/unit/lookups/pelias_test.rb @@ -21,4 +21,10 @@ class PeliasTest < GeocoderTestCase query = Geocoder::Query.new('Madison Square Garden, New York, NY') assert_match 'size=1', query.url end + + def test_query_for_reverse_geocode + lookup = Geocoder::Lookup::Mapzen.new + url = lookup.query_url(Geocoder::Query.new([45.423733, -75.676333])) + assert_match(/point.lat=45.423733&point.lon=-75.676333&size=1/, url) + end end