This is driving me crazy. I have deleted this key 1000 times so far. Yesterday it worked like a charm, today not anymore Here is the python code:
from googlemaps
Since September 2013, Google Maps API v2 no longer works. Here is the code working for API v3 (based on this answer):
import urllib
import simplejson
googleGeocodeUrl = 'http://maps.googleapis.com/maps/api/geocode/json?'
def get_coordinates(query, from_sensor=False):
query = query.encode('utf-8')
params = {
'address': query,
'sensor': "true" if from_sensor else "false"
}
url = googleGeocodeUrl + urllib.urlencode(params)
json_response = urllib.urlopen(url)
response = simplejson.loads(json_response.read())
if response['results']:
location = response['results'][0]['geometry']['location']
latitude, longitude = location['lat'], location['lng']
print query, latitude, longitude
else:
latitude, longitude = None, None
print query, ""
return latitude, longitude
See official documentation for the complete list of parameters and additional information.