forecast.hours 端点会返回特定地理位置的最多 240 小时预报信息,从当前小时开始。API 会返回以下内容:
- 当前天气状况的说明,以及相应的图标
- 当前温度
- 体感温度
- 露点
- 热指数
- 风寒效应
- 湿灯泡温度
- 相对湿度传感器
- 紫外线指数
- 降水概率、百分比和类型
- 雷暴概率
- 海平面气压
- 风向、风速和阵风
- 能见度和云层覆盖率
借助 API Explorer,您可以发出实时请求,以便熟悉 API 和 API 选项:
每小时天气预报请求简介
如需请求每小时预报信息,请向以下网址发送 HTTP GET 请求:
https://weather.googleapis.com/v1/forecast/hours:lookup?key=YOUR_API_KEY&location.latitude=LATITUDE&location.longitude=LONGITUDE
在请求网址参数中添加相应位置的纬度和经度坐标。
每小时天气预报请求示例
默认情况下,forecast.hours 端点会返回 240 小时的数据(从当前小时开始)。您可以使用 hours
参数将请求范围限定为特定时间段。
以下示例请求加利福尼亚州山景城未来 3 小时的每小时预报信息:
curl -X GET "https://weather.googleapis.com/v1/forecast/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220 &location.longitude=-122.0841 &hours=3"
在响应中,interval
对象表示每个小时的信息:
{ "forecastHours": [ { "interval": { "startTime": "2025-02-05T23:00:00Z", "endTime": "2025-02-06T00:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 5, "hours": 15, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/sunny", "description": { "text": "Sunny", "languageCode": "en" }, "type": "CLEAR" }, "temperature": { "degrees": 12.7, "unit": "CELSIUS" }, "feelsLikeTemperature": { "degrees": 12, "unit": "CELSIUS" }, "dewPoint": { "degrees": 2.7, "unit": "CELSIUS" }, "heatIndex": { "degrees": 12.7, "unit": "CELSIUS" }, "windChill": { "degrees": 12, "unit": "CELSIUS" }, "wetBulbTemperature": { "degrees": 7.7, "unit": "CELSIUS" }, "relativeHumidity": 51, "uvIndex": 1, "precipitation": { "probability": { "percent": 0, "type": "RAIN" }, "qpf": { "quantity": 0, "unit": "MILLIMETERS" } }, "thunderstormProbability": 0, "airPressure": { "meanSeaLevelMillibars": 1019.13 }, "wind": { "direction": { "degrees": 335, "cardinal": "NORTH_NORTHWEST" }, "speed": { "value": 10, "unit": "KILOMETERS_PER_HOUR" }, "gust": { "value": 19, "unit": "KILOMETERS_PER_HOUR" } }, "visibility": { "distance": 16, "unit": "KILOMETERS" }, "cloudCover": 0, "iceThickness": { "thickness": 0, "unit": "MILLIMETERS" } }, { "interval": { "startTime": "2025-02-06T00:00:00Z", "endTime": "2025-02-06T01:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 5, "hours": 16, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/sunny", "description": { "text": "Sunny", "languageCode": "en" }, "type": "CLEAR" }, "temperature": { "degrees": 12.5, "unit": "CELSIUS" }, /.../ }, { "interval": { "startTime": "2025-02-06T01:00:00Z", "endTime": "2025-02-06T02:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 5, "hours": 17, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/sunny", "description": { "text": "Sunny", "languageCode": "en" }, "type": "CLEAR" }, "temperature": { "degrees": 11.4, "unit": "CELSIUS" }, /.../ } ], "timeZone": { "id": "America/Los_Angeles" } }
指定每页返回的小时数
您可以使用 pageSize
网址参数指定每页返回的数据时长。默认值为每页 24 小时的预报信息。
包含多页信息的响应包含 nextPageToken
。如需查看下一页信息,请将 nextPageToken
值传递到请求中的 pageToken
参数。
以下示例请求加利福尼亚州山景城 25 小时的天气预报数据,每页包含 3 小时的数据:
curl -X GET "https://weather.googleapis.com/v1/forecast/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220 &location.longitude=-122.0841 &hours=25&pageSize=3"
响应(包含前 3 小时的数据)的格式如下:
{ "forecastHours": [ { "interval": { "startTime": "2025-02-06T23:00:00Z", "endTime": "2025-02-07T00:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 6, "hours": 15, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/showers", "description": { "text": "Rain showers", "languageCode": "en" }, "type": "RAIN_SHOWERS" }, "temperature": { "degrees": 14.6, "unit": "CELSIUS" }, /.../ }, { "interval": { "startTime": "2025-02-07T00:00:00Z", "endTime": "2025-02-07T01:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 6, "hours": 16, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/drizzle", "description": { "text": "Light rain", "languageCode": "en" }, "type": "LIGHT_RAIN" }, "temperature": { "degrees": 14.4, "unit": "CELSIUS" }, /.../ }, { "interval": { "startTime": "2025-02-07T01:00:00Z", "endTime": "2025-02-07T02:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 6, "hours": 17, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, "temperature": { "degrees": 14.4, "unit": "CELSIUS" }, /.../ } ], "timeZone": { "id": "America/Los_Angeles" }, "nextPageToken": "ChYKEgm8dJMYBLZCQBH-ZffkYYVewBAZEAMYAyIMCLKClb0GEJeO18kDKhNBbWVyaWNhL0xvc19BbmdlbGVz" }
如需访问下一页数据,请将 nextPageToken
值传递到请求中的 pageToken
参数:
curl -X GET "https://weather.googleapis.com/v1/forecast/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220 &location.longitude=-122.0841 &hours=25 &pageSize=3 &pageToken=ChYKEgm8dJMYBLZCQBH-ZffkYYVewBAZEAMYAyIMCLKClb0GEJeO18kDKhNBbWVyaWNhL0xvc19BbmdlbGVz"
响应格式如下:
{ "forecastHours": [ { "interval": { "startTime": "2025-02-07T02:00:00Z", "endTime": "2025-02-07T03:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 6, "hours": 18, "utcOffset": "-28800s" }, "isDaytime": false, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, "temperature": { "degrees": 14.3, "unit": "CELSIUS" }, /.../ }, { "interval": { "startTime": "2025-02-07T03:00:00Z", "endTime": "2025-02-07T04:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 6, "hours": 19, "utcOffset": "-28800s" }, "isDaytime": false, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/showers", "description": { "text": "Rain showers", "languageCode": "en" }, "type": "RAIN_SHOWERS" }, "temperature": { "degrees": 14.2, "unit": "CELSIUS" }, /.../ }, { "interval": { "startTime": "2025-02-07T04:00:00Z", "endTime": "2025-02-07T05:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 6, "hours": 20, "utcOffset": "-28800s" }, "isDaytime": false, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/showers", "description": { "text": "Rain showers", "languageCode": "en" }, "type": "RAIN_SHOWERS" }, "temperature": { "degrees": 14.1, "unit": "CELSIUS" }, /.../ } ], "timeZone": { "id": "America/Los_Angeles" }, "nextPageToken": "ChYKEgm8dJMYBLZCQBH-ZffkYYVewBAZEAYYBiILCPeDlb0GEICs5TMqE0FtZXJpY2EvTG9zX0FuZ2VsZXM=" }
试试看!
借助 API Explorer,您可以发出示例请求,以便熟悉 API 和 API 选项。
选择页面右侧的 API 图标 api。
(可选)修改请求参数。
选择执行按钮。在对话框中,选择您要使用哪个账号发出请求。
在 APIs Explorer 面板中,选择全屏图标 fullscreen 以展开 APIs Explorer 窗口。