def rawGeocoder(self, query):
# http://stackoverflow.com/questions/9884475/using-google-maps-geocoder-from-python-with-urllib2
add = query + ", Argentina"
add = urllib2.quote(add.encode('utf8'))
geocode_url = "http://maps.googleapis.com/maps/api/geocode/json?language=es&address=%s&sensor=false" % add
req = urllib2.urlopen(geocode_url)
res = json.loads(req.read())
# comprehension para parsear lo devuelto por el google geocoder
ret = [
{
'nombre' : i["formatted_address"],
'precision': len(i["address_components"]) / 6,
'geom' : "POINT(" + str(i["geometry"]["location"]["lng"]) + " " + str(i["geometry"]["location"]["lat"]) + ")",
'tipo' : "rawGeocoder"
}
for i in res["results"]
]
return ret
评论列表
文章目录