def fetch(self, point, key=conf.GOOGLE_MAPS_KEY):
if not key:
return self.fallback()
try:
async with ClientSession(loop=LOOP) as session:
async with session.get(
'https://maps.googleapis.com/maps/api/elevation/json',
params={'locations': '{0[0]},{0[1]}'.format(point),
'key': key},
timeout=10) as resp:
response = await resp.json(loads=json_loads)
altitude = response['results'][0]['elevation']
self.altitudes[point] = altitude
self.changed = True
return altitude
except CancelledError:
raise
except Exception:
try:
self.log.error(response['error_message'])
except (KeyError, NameError):
self.log.error('Error fetching altitude for {}.', point)
return self.fallback()
评论列表
文章目录