ปลายทาง forecast.hours จะแสดงข้อมูลการพยากรณ์อากาศสูงสุด 240 ชั่วโมงสำหรับ สถานที่ตั้งที่เฉพาะเจาะจง โดยเริ่มตั้งแต่ชั่วโมงปัจจุบัน API จะแสดงข้อมูลต่อไปนี้
- คำอธิบายสภาพอากาศปัจจุบัน พร้อมไอคอนที่เกี่ยวข้อง
- อุณหภูมิปัจจุบัน
- อุณหภูมิที่รู้สึกได้
- จุดน้ำค้าง
- ดัชนีความร้อน
- ลมหนาว
- อุณหภูมิกระเปาะเปียก
- ความชื้นสัมพัทธ์
- ดัชนีรังสียูวี
- ความน่าจะเป็น เปอร์เซ็นต์ และประเภท ของฝน
- ความน่าจะเป็นของการเกิดพายุฝนฟ้าคะนอง
- ความกดอากาศที่ระดับน้ำทะเล
- ทิศทาง ความเร็ว และลมกระโชก
- ทัศนวิสัยและปริมาณเมฆ
โปรแกรมสำรวจ API ช่วยให้คุณส่งคำขอแบบเรียลไทม์เพื่อให้คุ้นเคยกับ API และตัวเลือก API ดังนี้
เกี่ยวกับคำขอพยากรณ์รายชั่วโมง
หากต้องการขอข้อมูลพยากรณ์อากาศรายชั่วโมง ให้ส่งคำขอ HTTP GET ไปยัง
https://weather.googleapis.com/v1/forecast/hours:lookup?key=YOUR_API_KEY&location.latitude=LATITUDE&location.longitude=LONGITUDE
ใส่พิกัดละติจูดและลองจิจูดของสถานที่ตั้งในคำขอ URL พารามิเตอร์
ตัวอย่างคำขอพยากรณ์รายชั่วโมง
โดยค่าเริ่มต้นแล้ว Endpoint
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" } }
ระบุจำนวนชั่วโมงที่จะแสดงต่อหน้า
คุณระบุจำนวนชั่วโมงของข้อมูลที่จะแสดงผลต่อหน้าได้โดยใช้พารามิเตอร์ URL 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 ช่วยให้คุณส่งคำขอตัวอย่างได้ เพื่อให้คุ้นเคยกับ API และตัวเลือก API
เลือกไอคอน API api ทางด้านขวาของหน้า
แก้ไขพารามิเตอร์คำขอ (ไม่บังคับ)
เลือกปุ่มดำเนินการ ในกล่องโต้ตอบ ให้เลือกบัญชี ที่ต้องการใช้เพื่อส่งคำขอ
ในแผงโปรแกรมสำรวจ API ให้เลือกไอคอนเต็มหน้าจอ fullscreen เพื่อขยายหน้าต่างโปรแกรมสำรวจ API