Posted on

Geocoding with python

There is a lot of services that provide geocoding or reverse geocoding. In this example I would like to show you an easy way how to implement one of this service, datasciencetoolkit ( in python script. Big advantage of this service is that you dont need to register to get a key.

Firstly, you will need urllib and json modules to be imported. Then, it is quite easy, just request the url and parse the response. Use “loads” method from json module to get json object. Path for getting coordinates is [‘results’][0][‘geometry’][‘location’] (In case geocoding succeed and you want the first occurrence). 

The code is very simple:

The same achieved using requests module:


Other possible solutions I have found or have had experiences with are APIs from yahoo, google or bing. There is a nice blog with their comparison here