Điểm cuối forecast.hours trả về thông tin dự báo trong tối đa 240 giờ cho một vị trí cụ thể, bắt đầu từ giờ hiện tại. API trả về những thông tin sau:
- Nội dung mô tả tình hình thời tiết hiện tại cùng với biểu tượng tương ứng
- Nhiệt độ hiện tại
- Nhiệt độ rõ ràng ("nhiệt độ cảm giác")
- Điểm sương
- Chỉ số nhiệt
- Gió lạnh
- Nhiệt độ bầu ướt
- Độ ẩm tương đối
- Chỉ số UV
- Xác suất, tỷ lệ phần trăm và loại mưa
- Xác suất có giông bão
- Áp suất mực nước biển
- Hướng, tốc độ và luồng gió
- Mức độ che phủ của mây và tầm nhìn
Trình khám phá API cho phép bạn tạo các yêu cầu trực tiếp để làm quen với API và các tuỳ chọn API:
Giới thiệu về yêu cầu dự báo hằng giờ
Để yêu cầu thông tin dự báo hằng giờ, hãy gửi yêu cầu HTTP GET đến:
https://weather.googleapis.com/v1/forecast/hours:lookup?key=YOUR_API_KEY&location.latitude=LATITUDE&location.longitude=LONGITUDE
Thêm toạ độ vĩ độ và kinh độ của vị trí vào tham số URL yêu cầu.
Ví dụ về yêu cầu dự báo hằng giờ
Theo mặc định, điểm cuối forecast.hours sẽ trả về 240 giờ dữ liệu, bắt đầu từ giờ hiện tại. Bạn có thể đặt phạm vi yêu cầu của mình thành một khoảng thời gian cụ thể bằng cách sử dụng tham số hours.
Ví dụ sau đây yêu cầu thông tin dự báo hằng giờ trong 3 giờ tới cho Mountain View, California:
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"
Trong phản hồi, đối tượng interval cho biết thông tin của từng giờ:
{ "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" } }
Chỉ định số giờ sẽ trả về trên mỗi trang
Bạn có thể chỉ định số giờ dữ liệu cần trả về trên mỗi trang bằng cách sử dụng tham số URL pageSize. Giá trị mặc định là thông tin dự báo trong 24 giờ trên mỗi trang.
Các phản hồi có nhiều trang thông tin sẽ bao gồm nextPageToken. Để xem trang thông tin tiếp theo, hãy truyền giá trị nextPageToken vào tham số pageToken trong yêu cầu của bạn.
Ví dụ sau yêu cầu dữ liệu dự báo thời tiết trong 25 giờ cho Mountain View, California, với 3 giờ dữ liệu trên mỗi trang:
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"
Phản hồi, bao gồm dữ liệu trong 3 giờ đầu tiên, có dạng:
{ "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" }
Để truy cập vào trang dữ liệu tiếp theo, hãy truyền giá trị nextPageToken vào tham số pageToken trong yêu cầu của bạn:
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"
Phản hồi có dạng:
{ "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=" }
Hãy dùng thử!
Trình khám phá API cho phép bạn tạo các yêu cầu mẫu để quen thuộc với API và các tuỳ chọn API.
Chọn biểu tượng API api ở bên phải trang.
Bạn có thể chỉnh sửa các tham số yêu cầu (không bắt buộc).
Chọn nút Thực thi. Trong hộp thoại, hãy chọn tài khoản mà bạn muốn sử dụng để gửi yêu cầu.
Trong bảng điều khiển Trình khám phá API, hãy chọn biểu tượng toàn màn hình fullscreen để mở rộng cửa sổ Trình khám phá API.