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
评论列表
文章目录