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 |
常見用途
- 即時天氣和天氣更新資訊主頁:使用 GPS 座標 (
location.latitude和location.longitude) 或經過地理編碼的城市座標,查詢currentConditions:lookup、forecast/hours:lookup和forecast/days:lookup,顯示自動更新的溫度、濕度和風速。 - 路線天氣疊加層:從 Routes API 沿著路線折線取樣經緯度路線控點,並在每個路線控點的預估抵達時間呼叫
currentConditions:lookup或forecast/hours:lookup,提醒駕駛人天氣狀況變化。 - 根據天氣追蹤健康、水分和活動:從
currentConditions:lookup擷取當地temperature、feelsLikeTemperature、relativeHumidity、heatIndex和uvIndex,調整每日水分目標或戶外運動建議。
Weather API 的功能
Weather API 資料包含:
- 天氣狀況和圖示:
weatherCondition中目前天氣狀況的說明和對應圖示 (例如「多雲」或「局部陣雪」)。 - 溫度:目前溫度 (
temperature)、最低和最高溫度 (每日預報中的minTemperature和maxTemperature,或currentConditionsHistory內),以及體感溫度 (feelsLikeTemperature)。 - 降水:總降水量和降水類型 (雪、雨、冰、混合)。
- 風:風寒指數 (
windChill)、風向 (wind.direction)、風速 (wind.speed) 和陣風 (wind.gust)。 - 冰層厚度:冰層的厚度。
- 濕度:露點 (
dewPoint)、熱指數 (heatIndex)、濕球溫度 (wetBulbTemperature) 和相對濕度 (relativeHumidity)。 - 紫外線指數:紫外線 (UV) 指數 (
uvIndex)。 - 雷暴機率:發生雷暴的機率百分比。
- 能見度:可清楚看見物體的距離。
- 氣壓:平均海平面氣壓。
- 日出和月出事件:日出、日落、月出和月落時間。
- 雲量:雲層覆蓋天空的百分比。
如何使用 Weather API
| 1 | 做好準備 | 請先設定 Google Cloud 專案,然後按照後續操作說明完成設定。 |
| 2 | 取得目前天氣資訊 | 請參閱「取得目前狀況」。 |
| 3 | 取得每小時天氣預報 | 請參閱「取得每小時天氣預報」。 |
| 4 | 取得每日天氣預報 | 請參閱「取得每日預測」。 |
| 5 | 取得每小時記錄 | 請參閱「取得每小時記錄」。 |
| 6 | 接收天氣警示 | 請參閱「接收天氣快訊」。 |
相關環境 API
如需空氣品質指數 (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)