DenisCarriere / geocoder

:earth_asia: Python Geocoder
http://geocoder.readthedocs.org
MIT License
1.61k stars 284 forks source link

Reverse geocoding support for OpenStreetMap and LocationIQ geocoders #353

Open jmourelos opened 6 years ago

jmourelos commented 6 years ago

First of all thanks for this awesome library.

I was trying to do some reverse geocoding with LocationIQ: geocoder.locationiq([latitude, longitude], method='reverse', key='...')

But I am getting the following error: Status code 404 from https://locationiq.org/v1/search.php: ERROR - 404 Client Error: Not Found for url: https://locationiq.org/v1/search.php?key=...

I looked into their documentation and they specified the following URL for reverse geocoding: https://locationiq.org/v1/reverse.phpkey=YOUR_API_KEY&lat=LATITUDE&lon=LONGITUDE&format=json

At the same time as far as I understand they use internally OSM so I would expect the geocoder for both providers to show reverse geocoding, but it's missing in geocoder OSM documentation.

I am willing to contribute on this topic, but I would like to first clarify if there is a real problem or if it's me just not understanding something.

jmourelos commented 6 years ago

I have been debugging this and the problem seems to be in how the coordinates are parsed/transformed:

LocationIQReverse([52.52, 13.40]) gives a wrong result, looks like the query with the coordinates in the generated URL is malformed.

LocationIQReverse("52.52, 13.40") gives the right result.

g-mc commented 6 years ago

@jmourelos ,

I came across the same issue as you while trying to use reverse geocoding from LocationIQ, #359 is my attempt to fix it. I didn't look at the OpenStreetMap reverse geocoding yet but I will try to check it out now that I got the other one working.

jmourelos commented 6 years ago

@g-mc ,

I thought initially that the "reverse.php" endpoint was LocationIQ specific, but I see now that it's a Nominatim endpoint. Checking their git history I see It's there at least since 2010.

That leads me to think that your solution should be applied also/to OSM, but probably that deserves a deeper look.

g-mc commented 6 years ago

I wanted to keep that PR as small as possible and didn't have a chance to look into the other one yet. I will try to take a look later today and work on a separate PR to hopefully fix the second part of this issue.