Created
July 27, 2012 15:29
-
-
Save maurobaraldi/3188673 to your computer and use it in GitHub Desktop.
Prodemg Nodes lat/long
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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