def direccionPostal(self, calle, numero, ciudad_slug):
# http://stackoverflow.com/questions/9884475/using-google-maps-geocoder-from-python-with-urllib2
import urllib2
import json
add = calle + " " + numero + ", " + ciudad_slug + ", 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': 1,
'geom' : "POINT(" + str(i["geometry"]["location"]["lng"]) + " " + str(i["geometry"]["location"]["lat"]) + ")",
'tipo' : "direccionPostal"
}
for i in res["results"]
if "street_address" in i["types"]
]
return ret
评论列表
文章目录