models.py 文件源码

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

项目:django-happenings 作者: natgeosociety 项目源码 文件源码
def geocode_address(self):
        """
        Set the lat_long field, if the appropriate fields are filled
        """
        from geopy.geocoders import Nominatim
        from geopy.exc import GeopyError

        address = self.one_line_address()
        if address:
            geolocator = Nominatim()
            try:
                location = geolocator.geocode(address)
                self.lat_long = {
                    "type": "Point",
                    "coordinates": [location.longitude, location.latitude]
                }
            except (GeopyError, AttributeError):
                pass
        return
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号