managers.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:old-web 作者: cualbondi 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号