Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Created March 16, 2017 15:57
Show Gist options
  • Save toast38coza/e54cf4db02bf44ebf7e52c87f58e5b3e to your computer and use it in GitHub Desktop.
Save toast38coza/e54cf4db02bf44ebf7e52c87f58e5b3e to your computer and use it in GitHub Desktop.
Playing around with What.Three.Words in python
# pip install what3words
# setup:
api_key = environ['W3W_API_KEY']
w3w = what3words.Geocoder(api_key)
# forward: 3 words to address:
In [18]: w3w.forward(addr='prom.cape.pump')
Out[18]:
{u'bounds': {u'northeast': {u'lat': 51.484476, u'lng': -0.195383},
u'southwest': {u'lat': 51.484449, u'lng': -0.195426}},
u'crs': {u'properties': {u'href': u'http://spatialreference.org/ref/epsg/4326/ogcwkt/',
u'type': u'ogcwkt'},
u'type': u'link'},
u'geometry': {u'lat': 51.484463, u'lng': -0.195405},
u'language': u'en',
u'map': u'http://w3w.co/prom.cape.pump',
u'status': {u'reason': u'OK', u'status': 200},
u'thanks': u'Thanks from all of us at index.home.raft for using a what3words API',
u'words': u'prom.cape.pump'}
# reverse (lat, lng) => 3 words:
In [21]: data = {"lat":51.484463,"lng":-0.195405}
In [22]: w3w.reverse(**data)
Out[22]:
{u'bounds': {u'northeast': {u'lat': 51.484476, u'lng': -0.195383},
u'southwest': {u'lat': 51.484449, u'lng': -0.195426}},
u'crs': {u'properties': {u'href': u'http://spatialreference.org/ref/epsg/4326/ogcwkt/',
u'type': u'ogcwkt'},
u'type': u'link'},
u'geometry': {u'lat': 51.484463, u'lng': -0.195405},
u'language': u'en',
u'map': u'http://w3w.co/prom.cape.pump',
u'status': {u'reason': u'OK', u'status': 200},
u'thanks': u'Thanks from all of us at index.home.raft for using a what3words API',
u'words': u'prom.cape.pump'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment