Skip to content

Instantly share code, notes, and snippets.

@jboynyc
Last active March 23, 2016 09:56
Show Gist options
  • Save jboynyc/b66517df3076d33275af to your computer and use it in GitHub Desktop.
Save jboynyc/b66517df3076d33275af to your computer and use it in GitHub Desktop.
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
@jboynyc
Copy link
Author

jboynyc commented Mar 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment