Skip to content

Instantly share code, notes, and snippets.

@DenisCarriere
Last active August 29, 2015 14:24
Show Gist options
  • Save DenisCarriere/ae18f7a6ce1400902dfb to your computer and use it in GitHub Desktop.
Save DenisCarriere/ae18f7a6ce1400902dfb to your computer and use it in GitHub Desktop.
Using Geonames
# Geocoding with Geonames in Python
>>> import geocoder
>>> g = geocoder.geonames("Museo Nacional de Antropología")
>>> g.json
{'address': 'Museo Nacional de Antropologia - INAH',
'code': 'MUS',
'country': 'Mexico',
'description': 'museum',
'encoding': 'utf-8',
'geometry': {'coordinates': ['-99.18633', '19.42613'], 'type': 'Point'},
'geonames_id': 6458949,
'lat': '19.42613',
'lng': '-99.18633',
'location': 'Museo Nacional de Antropolog\xc3\xada',
'method': 'geocode',
'ok': True,
'provider': 'geonames',
'state': 'Mexico City',
'status': 'OK'}
# Using Bash/Terminal
$ geocode "Museo Nacional de Antropología" -p geonames
{"status": "OK", "code": "MUS", "ok": true, "description": "museum", "encoding": "utf-8", "geometry": {"type": "Point", "coordinates": ["-99.18633", "19.42613"]}, "country": "Mexico", "provider": "geonames", "geonames_id": 6458949, "state": "Mexico City", "location": "Museo Nacional de Antropolog\u00eda", "address": "Museo Nacional de Antropologia - INAH", "lat": "19.42613", "lng": "-99.18633", "method": "geocode"}
@anndroid
Copy link

Thank you very much for your help Denis!
I have a question, what if there was a 'Museo Nacional de Antropología' at Guadalajara (a Mexico state), and another with the same name at Mexico City? How could I get just the one at Mexico city?, this because I am working with streets and commonly, streets from different places have the same name but different coordinates.
Thank you in advance.

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