ปลายทาง history.hours จะแสดงข้อมูลสภาพอากาศย้อนหลังรายชั่วโมงสูงสุด 24 ชั่วโมง ณ สถานที่ที่ระบุ โดยเริ่มจากชั่วโมงล่าสุด API จะแสดงข้อมูลต่อไปนี้
- คำอธิบายสภาพอากาศ พร้อมไอคอนที่เกี่ยวข้อง สำหรับชั่วโมงที่ระบุ
- อุณหภูมิสูงสุดและต่ำสุดรายวัน
- อุณหภูมิสูงสุดและต่ำสุดที่รู้สึกได้ ("รู้สึกเหมือน") ในแต่ละวัน
- จุดน้ำค้าง
- ดัชนีความร้อน
- อุณหภูมิกระเปาะเปียก
- ความชื้นสัมพัทธ์
- ดัชนีรังสียูวี
- ความน่าจะเป็น เปอร์เซ็นต์ ปริมาณ และประเภท ของฝน
- ความน่าจะเป็นของการเกิดพายุฝนฟ้าคะนอง
- ความกดอากาศที่ระดับน้ำทะเล
- ลมหนาว
- ทิศทาง ความเร็ว และลมกระโชก
- ความหนาของน้ำแข็ง
- ทัศนวิสัยและปริมาณเมฆ
โปรแกรมสำรวจ API ช่วยให้คุณส่งคำขอแบบเรียลไทม์เพื่อให้คุ้นเคยกับ API และตัวเลือก API ดังนี้
เกี่ยวกับคำขอประวัติรายชั่วโมง
หากต้องการขอข้อมูลประวัติรายชั่วโมง ให้ส่งคำขอ HTTP GET ไปยัง
https://weather.googleapis.com/v1/history/hours:lookup?key=YOUR_API_KEY&location.latitude=LATITUDE&location.longitude=LONGITUDE
ใส่พิกัดละติจูดและลองจิจูดของสถานที่ตั้งในคำขอ URL พารามิเตอร์
ตัวอย่างคำขอประวัติรายชั่วโมง
โดยค่าเริ่มต้น
history.hours
ปลายทางจะแสดงข้อมูลสภาพอากาศย้อนหลัง 24 ชั่วโมง โดยเริ่มจากชั่วโมงล่าสุด คุณกำหนดขอบเขตคำขอให้เป็นระยะเวลาที่เฉพาะเจาะจงได้โดยใช้พารามิเตอร์ hours
ตัวอย่างคำขอต่อไปนี้จะขอข้อมูลประวัติรายชั่วโมงในช่วง 3 ชั่วโมงที่ผ่านมาใน Mountain View รัฐแคลิฟอร์เนีย
curl -X GET "https://weather.googleapis.com/v1/history/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220 &location.longitude=-122.0841 &hours=3"
ในคำตอบ ออบเจ็กต์ interval
จะระบุข้อมูลแต่ละชั่วโมง
{ "historyHours": [ { "interval": { "startTime": "2025-02-12T22:00:00Z", "endTime": "2025-02-12T23:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 14, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, "temperature": { "degrees": 12.4, "unit": "CELSIUS" }, "feelsLikeTemperature": { "degrees": 12.4, "unit": "CELSIUS" }, "dewPoint": { "degrees": 6.1, "unit": "CELSIUS" }, "heatIndex": { "degrees": 12.4, "unit": "CELSIUS" }, "windChill": { "degrees": 12.4, "unit": "CELSIUS" }, "wetBulbTemperature": { "degrees": 9.1, "unit": "CELSIUS" }, "relativeHumidity": 65, "uvIndex": 1, "precipitation": { "probability": { "percent": 10, "type": "RAIN" }, "qpf": { "quantity": 0, "unit": "MILLIMETERS" } }, "thunderstormProbability": 0, "airPressure": { "meanSeaLevelMillibars": 1010.4 }, "wind": { "direction": { "degrees": 135, "cardinal": "SOUTHEAST" }, "speed": { "value": 3, "unit": "KILOMETERS_PER_HOUR" }, "gust": { "value": 6, "unit": "KILOMETERS_PER_HOUR" } }, "visibility": { "distance": 16, "unit": "KILOMETERS" }, "cloudCover": 95, "iceThickness": { "thickness": 0, "unit": "MILLIMETERS" } }, { "interval": { "startTime": "2025-02-12T21:00:00Z", "endTime": "2025-02-12T22:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 13, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ }, { "interval": { "startTime": "2025-02-12T20:00:00Z", "endTime": "2025-02-12T21:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 12, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ } ], "timeZone": { "id": "America/Los_Angeles" } }
ระบุจำนวนชั่วโมงที่จะแสดงต่อหน้า
คุณระบุจำนวนชั่วโมงของข้อมูลที่จะแสดงผลต่อหน้าได้โดยใช้พารามิเตอร์ URL pageSize
ค่าเริ่มต้นคือข้อมูลการคาดการณ์ 24 ชั่วโมง
ต่อหน้า
การตอบกลับที่มีข้อมูลหลายหน้าจะมี nextPageToken
หากต้องการดู
ข้อมูลหน้าถัดไป ให้ส่งค่า nextPageToken
ไปยัง
พารามิเตอร์ pageToken
ในคำขอ
ตัวอย่างต่อไปนี้ขอข้อมูลพยากรณ์อากาศ 8 ชั่วโมงสำหรับเมาน์เทนวิว แคลิฟอร์เนีย โดยมีข้อมูล 5 ชั่วโมงต่อหน้า
curl -X GET "https://weather.googleapis.com/v1/history/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220 &location.longitude=-122.0841 &hours=8&pageSize=5"
การตอบกลับซึ่งรวมถึงข้อมูล 3 ชั่วโมงแรกจะอยู่ในรูปแบบต่อไปนี้
{ "historyHours": [ { "interval": { "startTime": "2025-02-12T23:00:00Z", "endTime": "2025-02-13T00:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 15, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, "temperature": { "degrees": 11.6, "unit": "CELSIUS" }, "feelsLikeTemperature": { "degrees": 11.6, "unit": "CELSIUS" }, "dewPoint": { "degrees": 6.3, "unit": "CELSIUS" }, "heatIndex": { "degrees": 11.6, "unit": "CELSIUS" }, "windChill": { "degrees": 11.6, "unit": "CELSIUS" }, "wetBulbTemperature": { "degrees": 8.8, "unit": "CELSIUS" }, "relativeHumidity": 70, "uvIndex": 0, "precipitation": { "probability": { "percent": 10, "type": "RAIN" }, "qpf": { "quantity": 0, "unit": "MILLIMETERS" } }, "thunderstormProbability": 0, "airPressure": { "meanSeaLevelMillibars": 1010.07 }, "wind": { "direction": { "degrees": 65, "cardinal": "EAST_NORTHEAST" }, "speed": { "value": 5, "unit": "KILOMETERS_PER_HOUR" }, "gust": { "value": 10, "unit": "KILOMETERS_PER_HOUR" } }, "visibility": { "distance": 16, "unit": "KILOMETERS" }, "cloudCover": 95, "iceThickness": { "thickness": 0, "unit": "MILLIMETERS" } }, { "interval": { "startTime": "2025-02-12T22:00:00Z", "endTime": "2025-02-12T23:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 14, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ }, { "interval": { "startTime": "2025-02-12T21:00:00Z", "endTime": "2025-02-12T22:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 13, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ }, { "interval": { "startTime": "2025-02-12T20:00:00Z", "endTime": "2025-02-12T21:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 12, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ }, { "interval": { "startTime": "2025-02-12T19:00:00Z", "endTime": "2025-02-12T20:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 11, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ } ], "timeZone": { "id": "America/Los_Angeles" }, "nextPageToken": "ChYKEgm8dJMYBLZCQL0xvc19BbmdlbGVz" }
หากต้องการเข้าถึงข้อมูลในหน้าถัดไป ให้ส่งค่า nextPageToken
ไปยัง
พารามิเตอร์ pageToken
ในคำขอ
curl -X GET "https://weather.googleapis.com/v1/history/hours:lookup?key=YOUR_API_KEY&location.latitude=37.4220 &location.longitude=-122.0841 &hours=8 &pageSize=5 &pageToken=ChYKEgm8dJMYBLZCQL0xvc19BbmdlbGVz"
คำตอบจะอยู่ในรูปแบบต่อไปนี้
{ "historyHours": [ { "interval": { "startTime": "2025-02-12T18:00:00Z", "endTime": "2025-02-12T19:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 10, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, "temperature": { "degrees": 8.9, "unit": "CELSIUS" }, "feelsLikeTemperature": { "degrees": 8.9, "unit": "CELSIUS" }, "dewPoint": { "degrees": 5.9, "unit": "CELSIUS" }, "heatIndex": { "degrees": 8.9, "unit": "CELSIUS" }, "windChill": { "degrees": 8.9, "unit": "CELSIUS" }, "wetBulbTemperature": { "degrees": 7.3, "unit": "CELSIUS" }, "relativeHumidity": 82, "uvIndex": 1, "precipitation": { "probability": { "percent": 10, "type": "RAIN" }, "qpf": { "quantity": 0, "unit": "MILLIMETERS" } }, "thunderstormProbability": 0, "airPressure": { "meanSeaLevelMillibars": 1012.1 }, "wind": { "direction": { "degrees": 135, "cardinal": "SOUTHEAST" }, "speed": { "value": 3, "unit": "KILOMETERS_PER_HOUR" }, "gust": { "value": 8, "unit": "KILOMETERS_PER_HOUR" } }, "visibility": { "distance": 16, "unit": "KILOMETERS" }, "cloudCover": 100, "iceThickness": { "thickness": 0, "unit": "MILLIMETERS" } }, { "interval": { "startTime": "2025-02-12T17:00:00Z", "endTime": "2025-02-12T18:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 9, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ }, { "interval": { "startTime": "2025-02-12T16:00:00Z", "endTime": "2025-02-12T17:00:00Z" }, "displayDateTime": { "year": 2025, "month": 2, "day": 12, "hours": 8, "utcOffset": "-28800s" }, "isDaytime": true, "weatherCondition": { "iconBaseUri": "https://maps.gstatic.com/weather/v1/cloudy", "description": { "text": "Cloudy", "languageCode": "en" }, "type": "CLOUDY" }, /.../ } ], "timeZone": { "id": "America/Los_Angeles" } }
ลองใช้งาน
โปรแกรมสำรวจ API ช่วยให้คุณส่งคำขอตัวอย่างได้ เพื่อให้คุ้นเคยกับ API และตัวเลือก API
เลือกไอคอน API api ทางด้านขวาของหน้า
แก้ไขพารามิเตอร์คำขอ (ไม่บังคับ)
เลือกปุ่มดำเนินการ ในกล่องโต้ตอบ ให้เลือกบัญชี ที่ต้องการใช้เพื่อส่งคำขอ
ในแผงโปรแกรมสำรวจ API ให้เลือกไอคอนเต็มหน้าจอ fullscreen เพื่อขยายหน้าต่างโปรแกรมสำรวจ API