Skip to content

Instantly share code, notes, and snippets.

@maurobaraldi
Created July 27, 2012 15:29
Show Gist options
  • Save maurobaraldi/3188673 to your computer and use it in GitHub Desktop.
Save maurobaraldi/3188673 to your computer and use it in GitHub Desktop.
Prodemg Nodes lat/long
import json
import codecs
import requests
locales = '/tmp/localidades_prodemg.csv'
with codecs.open(locales,'r','utf-8') as fp:
lines = fp.readlines()
def Lat_Lng(logradouro, cidade):
url = 'http://maps.googleapis.com/maps/api/geocode/json?address=%s,%s,%s,%s&sensor=false&sensor=false'
json_data = json.loads(requests.get(url % (logradouro, cidade,'Minas Gerais', 'Brasil')).content)
lat = json_data['results'][0]['geometry']['location']['lat']
lng = json_data['results'][0]['geometry']['location']['lng']
return [lat, lng]
for line in lines[1::]:
print line.split(';')[9], Lat_Lng(line.split(';')[8], line.split(';')[9])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment