Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion geocoder/locationiq_reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
# coding: utf8

from __future__ import absolute_import

from geocoder.location import Location
from geocoder.locationiq import LocationIQQuery


class LocationIQReverse(LocationIQQuery):
provider = 'locationiq'
method = 'reverse'

_URL = 'https://locationiq.org/v1/reverse.php'

def _build_params(self, location, provider_key, **kwargs):
location = Location(location)
return {
'format': 'json',
'key': provider_key,
'lat': location.latitude,
'lon': location.longitude,
}

def _adapt_results(self, json_response):
return [json_response]


if __name__ == '__main__':
g = LocationIQReverse("45.3, -75.4")
g = LocationIQReverse("45.421106, -75.690308")
g.debug()
61 changes: 28 additions & 33 deletions tests/results/locationiq_reverse.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
[
{
"place_id": "85985426",
"licence": "API \u00a9 LocationIQ.org CC BY 4.0, Data \u00a9 OpenStreetMap contributors, ODbL 1.0",
"osm_type": "way",
"osm_id": "68588664",
"boundingbox": [
"45.4201768",
"45.4214404",
"-75.6908211",
"-75.6893108"
],
"lat": "45.4208154",
"lon": "-75.6901176990294",
"display_name": "Ottawa City Hall, 110, Laurier Avenue West, Golden Triangle, Centretown, Somerset, Ottawa, Ontario, K2P 2K1, Canada",
"class": "building",
"type": "yes",
"importance": 0.31303438301933,
"address": {
"building": "Ottawa City Hall",
"house_number": "110",
"road": "Laurier Avenue West",
"neighbourhood": "Golden Triangle",
"suburb": "Centretown",
"city_district": "Somerset",
"city": "Ottawa",
"state": "Ontario",
"postcode": "K2P 2K1",
"country": "Canada",
"country_code": "ca"
}
}
]
{
"place_id": "90622554",
"licence": "\u00a9 LocationIQ.org CC BY 4.0, Data \u00a9 OpenStreetMap contributors, ODbL 1.0",
"osm_type": "way",
"osm_id": "68588664",
"lat": "45.4208154",
"lon": "-75.6901176990294",
"display_name": "Ottawa City Hall, 110, Laurier Avenue West, Golden Triangle, Centretown, Somerset, Ottawa, Ontario, K2P 2K1, Canada",
"address": {
"address29": "Ottawa City Hall",
"house_number": "110",
"road": "Laurier Avenue West",
"neighbourhood": "Golden Triangle",
"suburb": "Centretown",
"city_district": "Somerset",
"city": "Ottawa",
"state": "Ontario",
"postcode": "K2P 2K1",
"country": "Canada",
"country_code": "ca"
},
"boundingbox": [
"45.4201768",
"45.4214404",
"-75.6908211",
"-75.6893108"
]
}
2 changes: 1 addition & 1 deletion tests/test_locationiq.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_locationiq_multi_result():


def test_locationiq_reverse():
url = 'https://locationiq.org/v1/search.php?q=45.421106%2C+-75.690308&format=json&addressdetails=1&key=TEST_KEY'
url = 'https://locationiq.org/v1/reverse.php?format=json&key=TEST_KEY&lat=45.421106&lon=-75.690308'
data_file = 'tests/results/locationiq_reverse.json'
with requests_mock.Mocker() as mocker, open(data_file, 'r') as ip:
mocker.get(url, text=ip.read())
Expand Down