Last active
March 23, 2016 09:56
-
-
Save jboynyc/b66517df3076d33275af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
try: | |
from urllib.parse import urlencode | |
except ImportError: | |
from urllib import urlencode | |
def reverse_geocode(lng, lat, zoom=18): | |
OSM_API_URL = 'http://nominatim.openstreetmap.org/reverse?' | |
_headers = {'User-Agent': | |
'Identify your application in accordance with Nominatim API Usage Policy'} | |
params = {'format': 'json', 'zoom': zoom, 'lon': lng, 'lat': lat} | |
r = requests.get(OSM_API_URL + urlencode(params), headers=_headers) | |
if r.status_code == 200: | |
return r.json() | |
elif r.status_code == 404: | |
raise ValueError | |
else: | |
raise ConnectionError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nominatim Usage Policy