forecast
端点可提供指定位置最多 96 小时(4 天)的每小时空气质量预报信息。每份预报都包含每小时的空气质量指数以及其他信息:
- 预测的具体时间和日期或时间段
- 翻译后字段的语言代码
- 本地或自定义空气质量指数 (AQI)
- 健康状况建议
- 主要污染物
- 污染物浓度
- 有关污染物的其他信息
- 响应页面大小
- 调色板
借助 API Explorer,您可以发出实时请求,以便熟悉 API 和 API 选项:
预测请求简介
您可以通过向以下网址发送 HTTP POST 请求,使用 forecast 端点请求每小时空气质量预报信息:
https://airquality.googleapis.com/v1/forecast:lookup?key=YOUR_API_KEY
在请求正文中添加参数。请求正文包含您要获取空气质量每小时预报信息的位置,以及用于控制要在响应中包含哪些附加信息的各种选项。
关于预测响应
响应正文提供要显示空气质量预报信息、空气质量指数和其他自定义信息的世界协调时间 (UTC) 日期和时间。如果信息无法容纳在请求的页面大小内,响应正文还会包含用于检索下一页的令牌。
基本请求示例
以下代码展示了如何构建天气预报请求。在此示例中,您可以指定要显示每小时空气质量预报信息的位置、日期和时间(从下一小时开始,最长可达 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" }
试试看!
借助 API Explorer,您可以发出示例请求,以便熟悉 API 和 API 选项。
选择页面右侧的 API 图标 api。
(可选)修改请求参数。
选择执行按钮。在对话框中,选择您要用于提出请求的账号。
在 APIs Explorer 面板中,选择全屏图标 全屏 以展开 APIs Explorer 窗口。