Weather API 概览

借助 Weather API,您可以请求全球各地的实时超本地化天气数据,为实时天气信息中心、天气更新应用、路线天气叠加层以及基于天气的健康或活动追踪器提供支持。天气信息包括当前温度、降水、相对湿度、风速、紫外线指数等。

对于给定纬度和经度的位置,该 API 会为下表中的数据提供端点 (https://weather.googleapis.com/v1/...)。

REST 端点概览

API 端点 网址 说明 记录的参数
当前天气状况 https://weather.googleapis.com/v1/currentConditions:lookup 实时天气状况 location.latitude、location.longitude
每小时天气预报 https://weather.googleapis.com/v1/forecast/hours:lookup 未来长达 240 小时的天气预报 location.latitude、location.longitude
每日天气预报 https://weather.googleapis.com/v1/forecast/days:lookup 最多可预测未来 10 天的天气状况 location.latitude、location.longitude
每小时历史记录 https://weather.googleapis.com/v1/history/hours:lookup 最多可缓存 24 小时的过往状况 location.latitude、location.longitude
恶劣天气预警 https://weather.googleapis.com/v1/publicAlerts:lookup 恶劣天气预警 key、location.latitude、location.longitude

常见应用场景

Weather API 的功能

Weather API 数据包括以下内容:

如何使用 Weather API

1 设置 从设置 Google Cloud 项目开始,然后完成后续说明。
2 获取当前天气状况 请参阅获取当前天气状况。
3 获取每小时天气预报 请参阅获取每小时天气预报。
4 获取每日天气预报 请参阅获取每日预测。
5 获取每小时历史记录 请参阅获取每小时历史记录。
6 接收天气警报 请参阅接收天气提醒。

如需获取空气质量指数 (AQI) 和颗粒污染物(PM2.5、PM10)数据,请使用 Air Quality API (https://airquality.googleapis.com/v1/currentConditions:lookup)。Weather API 不会返回这些值。

其他相关的环境 API 包括:

  • 花粉量:Pollen API (https://pollen.googleapis.com/v1/forecast:lookup)
  • 太阳辐射和屋顶潜力:Solar API (https://solar.googleapis.com/v1/buildingInsights:findClosest)

后续步骤