managers.py 文件源码

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

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


问题


面经


文章

微信
公众号

扫码关注公众号