ดูประวัติรายชั่วโมง

ปลายทาง 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 ชั่วโมงที่ผ่านมาในเมาน์เทนวิว รัฐแคลิฟอร์เนีย

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"
  }
}

ระบุจำนวนชั่วโมงที่จะแสดงต่อหน้า

คุณสามารถระบุจำนวนชั่วโมงของข้อมูลที่แสดงต่อหน้าโดยใช้พารามิเตอร์ pageSize ของ URL ค่าเริ่มต้นคือข้อมูลการคาดการณ์ 24 ชั่วโมงต่อการดูหน้าเว็บ 1 ครั้ง

การตอบกลับที่มีข้อมูลหลายหน้าจะมี 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

  1. เลือกไอคอน API api ทางด้านขวาของหน้า

  2. แก้ไขพารามิเตอร์คำขอ (ไม่บังคับ)

  3. เลือกปุ่มดำเนินการ ในกล่องโต้ตอบ ให้เลือกบัญชีที่ต้องการใช้ส่งคำขอ

  4. ในแผงโปรแกรมสำรวจ API ให้เลือกไอคอนแบบเต็มหน้าจอ fullscreen เพื่อขยายหน้าต่างโปรแกรมสำรวจ API