history.hours 端點會傳回特定位置過去 24 小時內每小時的歷史天氣資料,API 會傳回以下內容:
- 描述特定小時的天氣狀況,並附上對應的圖示
- 每日最高溫和最低溫
- 每日最高和最低感溫度
- 露點
- 熱指數
- 溼球溫度
- 相對濕度
- 紫外線指數
- 降水的機率、百分比、數量和類型
- 雷雨機率
- 海平面氣壓
- 風寒
- 風方向、風速和陣風
- 冰層厚度
- 能見度和雲層覆蓋率
您可以透過 APIs Explorer 提出即時要求,熟悉 API 和 API 選項:
關於每小時記錄要求
如要要求每小時歷史記錄資訊,請傳送 HTTP GET 要求至:
https://weather.googleapis.com/v1/history/hours:lookup?key=YOUR_API_KEY&location.latitude=LATITUDE&location.longitude=LONGITUDE
請在要求網址參數中加入位置的經緯度座標。
每小時記錄要求範例
根據預設,history.hours 端點會傳回 24 小時的歷來天氣資料,從過去一小時開始。您可以使用 hours
參數,將要求範圍限定在特定時間範圍內。
以下範例會要求加州山景市過去三小時的每小時歷史資料:
curl -X GET "https://weather.googleapis.com/v1/history/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220 &location.longitude=-122.0841 &hours=3"
在回應中,interval
物件會指出每小時的資訊:
{ "historyHours": [ { "interval": { "startTime": "2025-02-12T22:00:00Z", "endTime": "2025-02-12T23:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 14, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, "temperature": { "degrees": 12.4, "unit": "CELSIUS" }, "feelsLikeTemperature": { "degrees": 12.4, "unit": "CELSIUS" }, "dewPoint": { "degrees": 6.1, "unit": "CELSIUS" }, "heatIndex": { "degrees": 12.4, "unit": "CELSIUS" }, "windChill": { "degrees": 12.4, "unit": "CELSIUS" }, "wetBulbTemperature": { "degrees": 9.1, "unit": "CELSIUS" }, "relativeHumidity": 65, "uvIndex": 1, "precipitation": { "probability": { "percent": 10, "type": "RAIN" }, "qpf": { "quantity": 0, "unit": "MILLIMETERS" } }, "thunderstormProbability": 0, "airPressure": { "meanSeaLevelMillibars": 1010.4 }, "wind": { "direction": { "degrees": 135, "cardinal": "SOUTHEAST" }, "speed": { "value": 3, "unit": "KILOMETERS_PER_HOUR" }, "gust": { "value": 6, "unit": "KILOMETERS_PER_HOUR" } }, "visibility": { "distance": 16, "unit": "KILOMETERS" }, "cloudCover": 95, "iceThickness": { "thickness": 0, "unit": "MILLIMETERS" } }, { "interval": { "startTime": "2025-02-12T21:00:00Z", "endTime": "2025-02-12T22:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 13, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ }, { "interval": { "startTime": "2025-02-12T20:00:00Z", "endTime": "2025-02-12T21:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 12, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ } ], "timeZone": { "id": "America/Los_Angeles" } }
指定每頁要傳回的時間數量
您可以使用 pageSize
網址參數,指定每頁傳回的資料時數。預設值為每頁 24 小時的預測資訊。
包含多頁資訊的回應會附上 nextPageToken
。如要查看下一頁資訊,請將 nextPageToken
值傳遞至要求中的 pageToken
參數。
以下範例會要求加州山景市的八小時天氣預報資料,每頁五小時:
curl -X GET "https://weather.googleapis.com/v1/history/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220 &location.longitude=-122.0841 &hours=8&pageSize=5"
回應包含前三小時的資料,格式如下:
{ "historyHours": [ { "interval": { "startTime": "2025-02-12T23:00:00Z", "endTime": "2025-02-13T00:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 15, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, "temperature": { "degrees": 11.6, "unit": "CELSIUS" }, "feelsLikeTemperature": { "degrees": 11.6, "unit": "CELSIUS" }, "dewPoint": { "degrees": 6.3, "unit": "CELSIUS" }, "heatIndex": { "degrees": 11.6, "unit": "CELSIUS" }, "windChill": { "degrees": 11.6, "unit": "CELSIUS" }, "wetBulbTemperature": { "degrees": 8.8, "unit": "CELSIUS" }, "relativeHumidity": 70, "uvIndex": 0, "precipitation": { "probability": { "percent": 10, "type": "RAIN" }, "qpf": { "quantity": 0, "unit": "MILLIMETERS" } }, "thunderstormProbability": 0, "airPressure": { "meanSeaLevelMillibars": 1010.07 }, "wind": { "direction": { "degrees": 65, "cardinal": "EAST_NORTHEAST" }, "speed": { "value": 5, "unit": "KILOMETERS_PER_HOUR" }, "gust": { "value": 10, "unit": "KILOMETERS_PER_HOUR" } }, "visibility": { "distance": 16, "unit": "KILOMETERS" }, "cloudCover": 95, "iceThickness": { "thickness": 0, "unit": "MILLIMETERS" } }, { "interval": { "startTime": "2025-02-12T22:00:00Z", "endTime": "2025-02-12T23:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 14, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ }, { "interval": { "startTime": "2025-02-12T21:00:00Z", "endTime": "2025-02-12T22:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 13, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ }, { "interval": { "startTime": "2025-02-12T20:00:00Z", "endTime": "2025-02-12T21:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 12, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ }, { "interval": { "startTime": "2025-02-12T19:00:00Z", "endTime": "2025-02-12T20:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 11, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ } ], "timeZone": { "id": "America/Los_Angeles" }, "nextPageToken": "ChYKEgm8dJMYBLZCQL0xvc19BbmdlbGVz" }
如要存取下一頁的資料,請將 nextPageToken
值傳遞至要求中的 pageToken
參數:
curl -X GET "https://weather.googleapis.com/v1/history/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220 &location.longitude=-122.0841 &hours=8 &pageSize=5 &pageToken=ChYKEgm8dJMYBLZCQL0xvc19BbmdlbGVz"
回應的格式如下:
{ "historyHours": [ { "interval": { "startTime": "2025-02-12T18:00:00Z", "endTime": "2025-02-12T19:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 10, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, "temperature": { "degrees": 8.9, "unit": "CELSIUS" }, "feelsLikeTemperature": { "degrees": 8.9, "unit": "CELSIUS" }, "dewPoint": { "degrees": 5.9, "unit": "CELSIUS" }, "heatIndex": { "degrees": 8.9, "unit": "CELSIUS" }, "windChill": { "degrees": 8.9, "unit": "CELSIUS" }, "wetBulbTemperature": { "degrees": 7.3, "unit": "CELSIUS" }, "relativeHumidity": 82, "uvIndex": 1, "precipitation": { "probability": { "percent": 10, "type": "RAIN" }, "qpf": { "quantity": 0, "unit": "MILLIMETERS" } }, "thunderstormProbability": 0, "airPressure": { "meanSeaLevelMillibars": 1012.1 }, "wind": { "direction": { "degrees": 135, "cardinal": "SOUTHEAST" }, "speed": { "value": 3, "unit": "KILOMETERS_PER_HOUR" }, "gust": { "value": 8, "unit": "KILOMETERS_PER_HOUR" } }, "visibility": { "distance": 16, "unit": "KILOMETERS" }, "cloudCover": 100, "iceThickness": { "thickness": 0, "unit": "MILLIMETERS" } }, { "interval": { "startTime": "2025-02-12T17:00:00Z", "endTime": "2025-02-12T18:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 9, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ }, { "interval": { "startTime": "2025-02-12T16:00:00Z", "endTime": "2025-02-12T17:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 8, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ } ], "timeZone": { "id": "America/Los_Angeles" } }
試試看!
您可以使用 APIs Explorer 建立範例要求,熟悉 API 和 API 選項。
選取頁面右側的 API 圖示 api。
視需要編輯要求參數。
選取「執行」按鈕。在對話方塊中,選擇要用來提出要求的帳戶。
在「API Explorer」面板中,選取全螢幕圖示 fullscreen 即可展開「API Explorer」視窗。