models.py 文件源码

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

项目:georef 作者: rukayaj 项目源码 文件源码
def _geolocate_google(self, string):
        g = GoogleV3()
        try:
            results = g.geocode(string, region='za')

            # Has it actually managed to find coords beyond province level? and are we in the right country?
            country = ''
            for address_component in results.raw['address_components']:
                if address_component['types'] == ['country', 'political']:
                    country = address_component['short_name']

            if country == 'ZA':
                # Get geographical position
                coords = results.raw['geometry']['location']
                ac = results.raw['address_components'][0]
                self.add_potential_georeference(long=coords['lng'],
                                                lat=coords['lat'],
                                                profile_name='Google',
                                                locality_name=ac['short_name'])

        except AttributeError as e:
            print("Google - not found: " + string + ' gives error : ' + str(sys.exc_info()))
            return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号