Blogue de Guillaume DALLAIRE's Blog

January 22, 2010

Easy geocoding with Google Maps using python

Filed under: python — Tags: , , , — gdallaire @ 5:16 pm

For a project, I had to resolve street address into geographic coordinates (geocode), here is a minimal piece of code using the Google Maps API Services :

import urllib
import json

def geocode(addr, api_key=''):
  url = "http://maps.google.com/maps/geo?q=%s&output=json&api_key=%s" % (urllib.quote(addr), urllib.quote(api_key))
  data = urllib.urlopen(url).read()
  return json.loads(data)['Placemark'][0]['Point']['coordinates']

data = geocode("1600 Amphitheatre Parkway Mountain View, CA 94043")
print "lat:%s long:%s" % (data[0], data[1])

October 26, 2008

Python

Filed under: python — Tags: , , — gdallaire @ 1:36 pm

The Python language is present in my life since about 1 year now. It’s hard to express how good it has been for me but this cartoon is a good example of “a picture is worth a thousand words”.  Here are some other good ones about Python too:

Powered by WordPress