Skip to content

Instantly share code, notes, and snippets.

@alesegdia
Last active August 29, 2015 14:09
Show Gist options
  • Save alesegdia/9fd6cd186744b6cf43c9 to your computer and use it in GitHub Desktop.
Save alesegdia/9fd6cd186744b6cf43c9 to your computer and use it in GitHub Desktop.
Get (lat,lon) from address using Nominatim and OSM in Python.
import urllib2
import json
import sys
def addr_to_url(addr):
return "http://nominatim.openstreetmap.org/?format=json&addressdetails=1&q=" + addr.strip().replace(" ", "+") + "&format=json&limit=1"
def addr_to_geo(addr):
url = addr_to_url(addr)
jsonreq = urllib2.urlopen(url).read()
data = json.loads(jsonreq)
return { key : data[0][key] for key in { "lat", "lon" } }
if len(sys.argv) != 2:
print 'Usage: python addr2geo "<address>"'
else:
print addr_to_geo(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment