forecast
端點可針對特定地點提供最多 96 小時 (4 天) 的每小時空氣品質預測資訊。每份預測都包含每小時的空氣品質指數和其他資訊:
- 預測的特定時間和日期或時間範圍
- 已翻譯欄位的語言代碼
- 當地或自訂空氣品質指數 (AQI)
- 健康推薦內容
- 主要汙染物
- 汙染物濃度
- 關於污染物的其他資訊
- 回應頁面大小
- 調色盤
您可以透過 APIs Explorer 提出即時要求,熟悉 API 和 API 選項:
預測請求簡介
您可以使用預測端點,透過 HTTP POST 要求傳送以下資訊,以便要求每小時空氣品質預測資訊:
https://airquality.googleapis.com/v1/forecast:lookup?key=YOUR_API_KEY
加入 參數 。要求主體包含您想要儲存的位置 像是取得每小時空氣品質天氣預報資訊,以及 控管要在回應中納入的其他資訊
關於預測回應
回應主體提供顯示廣播的日期和時間 (世界標準時間) 品質預測資訊、空氣品質指數和其他自訂 可能不準確或不適當回應主體也含有可擷取下一頁的權杖 。
基本要求範例
以下程式碼說明如何建構預測要求。在這個例子中 您指定的地區、日期和時間 (從下一個小時到 96 開始) 小時) 來顯示每小時的空氣品質預報資訊。
curl -X POST -d '{ "location": { "latitude": 37.4125333, "longitude": -122.0840937 }, "dateTime": "2024-02-09T08:00:00Z" }' \ -H "Content-Type: application/json" \ -H "Accept-Language: *" \ "https://airquality.googleapis.com/v1/forecast:lookup?key=YOUR_API_KEY"
呼叫會產生下列 JSON 回應。
{ "hourlyForecasts": [ { "dateTime": "2024-02-09T08:00:00Z", "indexes": [ { "code": "uaqi", "displayName": "Universal AQI", "aqi": 80, "aqiDisplay": "80", "color": { "red": 0.34509805, "green": 0.74509805, "blue": 0.20784314 }, "category": "Excellent air quality", "dominantPollutant": "pm25" } ] } ], "regionCode": "us" }
包含多個參數的要求範例
下列程式碼顯示如何使用多個 參數。在本範例中,您會指定下列項目:
- 位置
- 空氣品質預報資訊的顯示時間範圍
- 語言代碼
- 額外計算,例如健康相關建議、主要汙染物 濃度和其他汙染物資訊)
- 調色盤
curl -X POST -d '{ "pageSize": "10", "universalAqi": "true", "location": { "latitude": "40.741895", "longitude": "-73.989308" }, "period": { "startTime": "2024-02-27T13:58:14+02:00", "endTime": "2024-02-28T16:58:14+02:00" }, "languageCode": "en", "extraComputations": [ "HEALTH_RECOMMENDATIONS", "DOMINANT_POLLUTANT_CONCENTRATION", "POLLUTANT_ADDITIONAL_INFO" ], "uaqiColorPalette": "RED_GREEN" }' \ -H "Content-Type: application/json" \ -H "Accept-Language: *" \ "https://airquality.googleapis.com/v1/forecast:lookup?key=YOUR_API_KEY"
呼叫會產生下列 JSON 回應。
{ { "hourlyForecasts": [ { "dateTime": "2024-02-27T11:00:00Z", "indexes": [ { "code": "uaqi", "displayName": "Universal AQI", "aqi": 75, "aqiDisplay": "75", "color": { "red": 0.43137255, "green": 0.7764706, "blue": 0.20392157 }, "category": "Good air quality", "dominantPollutant": "pm25" } ], "pollutants": [ { "code": "pm25", "displayName": "PM2.5", "fullName": "Fine particulate matter (\u003c2.5µm)", "concentration": { "value": 15.1, "units": "MICROGRAMS_PER_CUBIC_METER" }, "additionalInfo": { "sources": "...", "effects": "..." } } ], "healthRecommendations": { "generalPopulation": "...", "lungDiseasePopulation": "...", "heartDiseasePopulation": "...", "athletes": "...", "pregnantWomen": "..." } }, { "dateTime": "2024-02-27T12:00:00Z", "indexes": [ { "code": "uaqi", "displayName": "Universal AQI", "aqi": 67, "aqiDisplay": "67", "color": { "red": 0.5882353, "green": 0.8392157, "blue": 0.16862746 }, "category": "Good air quality", "dominantPollutant": "pm25" } ], "pollutants": [ { "code": "pm25", "displayName": "PM2.5", "fullName": "Fine particulate matter (\u003c2.5µm)", "concentration": { "value": 19.96, "units": "MICROGRAMS_PER_CUBIC_METER" }, "additionalInfo": { "sources": "...", "effects": "..." } } ], "healthRecommendations": { "generalPopulation": "...", "lungDiseasePopulation": "...", "heartDiseasePopulation": "...", "athletes": "...", "pregnantWomen": "...", "children": "..." } }, /.../ ] } "regionCode": "us", "nextPageToken": "CjMKEglwCFVq9l5EQBH0aoDSUH9SwBoQCgYI1pDirgYSBgiGiOiuBiABKgMCBAMyAmVuOAEQGA==" }
如要查看下一頁的預測資訊,請傳入回應主體結尾處傳回的 nextPageToken
:
curl -X POST -d '{ "universalAqi": "true", "location": { "latitude": "40.741895", "longitude": "-73.989308" }, "period": { "startTime": "2024-02-27T13:58:14+02:00", "endTime": "2024-02-28T16:58:14+02:00" }, "languageCode": "en", "extraComputations": [ "HEALTH_RECOMMENDATIONS", "DOMINANT_POLLUTANT_CONCENTRATION", "POLLUTANT_ADDITIONAL_INFO" ], "uaqiColorPalette": "RED_GREEN", "pageToken": "CjMKEglwCFVq9l5EQBH0aoDSUH9SwBoQCgYI1pDirgYSBgiGiOiuBiABKgMCBAMyAmVuOAEQGA==" }' \ -H "Content-Type: application/json" \ -H "Accept-Language: *" \ "https://airquality.googleapis.com/v1/forecast:lookup?key=YOUR_API_KEY"
這會傳回預測資訊的下一頁:
{ "hourlyForecasts": [ { "dateTime": "2024-02-27T21:00:00Z", "indexes": [ { "code": "uaqi", "displayName": "Universal AQI", "aqi": 74, "aqiDisplay": "74", "color": { "red": 0.44705883, "green": 0.78431374, "blue": 0.2 }, "category": "Good air quality", "dominantPollutant": "o3" } ], "pollutants": [ { "code": "o3", "displayName": "O3", "fullName": "Ozone", "concentration": { "value": 32.07, "units": "PARTS_PER_BILLION" }, "additionalInfo": { "sources": "...", "effects": "..." } } ], "healthRecommendations": { "generalPopulation": "...", "elderly": "...", "lungDiseasePopulation": "...", "heartDiseasePopulation": "...", "athletes": "...", "pregnantWomen": "...", "children": "..." } }, { "dateTime": "2024-02-27T22:00:00Z", "indexes": [ { "code": "uaqi", "displayName": "Universal AQI", "aqi": 75, "aqiDisplay": "75", "color": { "red": 0.43137255, "green": 0.7764706, "blue": 0.20392157 }, "category": "Good air quality", "dominantPollutant": "o3" } ], "pollutants": [ { "code": "o3", "displayName": "O3", "fullName": "Ozone", "concentration": { "value": 30.94, "units": "PARTS_PER_BILLION" }, "additionalInfo": { "sources": "...", "effects": "..." } } ], "healthRecommendations": { "generalPopulation": "...", "lungDiseasePopulation": "...", "heartDiseasePopulation": "...", "athletes": "...", "pregnantWomen": "...", "children": "..." } }, /.../ ] "regionCode": "us" }