การคาดการณ์

ปลายทางการคาดการณ์จะแสดงข้อมูลการพยากรณ์คุณภาพอากาศรายชั่วโมงสูงสุด 96 ชั่วโมง (4 วัน) สำหรับสถานที่ที่ระบุ การคาดการณ์แต่ละรายการจะมีดัชนีคุณภาพอากาศรายชั่วโมงและข้อมูลเพิ่มเติมต่อไปนี้

  • เวลา วันที่ หรือระยะเวลาที่เจาะจงสำหรับการคาดการณ์
  • รหัสภาษาสำหรับช่องที่แปลแล้ว
  • ดัชนีคุณภาพอากาศ (AQI) ในท้องถิ่นหรือที่กำหนดเอง
  • คำแนะนำด้านสุขภาพ
  • สารมลพิษหลัก
  • ความเข้มข้นของสารมลพิษ
  • ข้อมูลเพิ่มเติมเกี่ยวกับสารมลพิษ
  • ขนาดหน้าคำตอบ
  • ชุดสี

เกี่ยวกับคำขอการคาดการณ์

คุณขอข้อมูลการพยากรณ์คุณภาพอากาศรายชั่วโมงโดยใช้ปลายทางการคาดการณ์ได้โดยส่งคำขอ HTTP POST ไปที่

https://airquality.googleapis.com/v1/forecast:lookup?key=YOUR_API_KEY

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

เกี่ยวกับการตอบกลับการคาดการณ์

เนื้อหาการตอบสนองจะระบุวันที่และเวลา UTC สำหรับแสดงข้อมูลการพยากรณ์คุณภาพอากาศ ดัชนีคุณภาพอากาศ และข้อมูลที่กำหนดเองเพิ่มเติม นอกจากนี้ เนื้อหาการตอบกลับยังรวมโทเค็นเพื่อดึงหน้าถัดไป หากข้อมูลไม่พอดีกับขนาดหน้าที่ขอ

ตัวอย่างคำขอพื้นฐาน

โค้ดต่อไปนี้แสดงวิธีการสร้างคำขอการคาดการณ์ ในตัวอย่างนี้ คุณระบุตำแหน่ง วันที่ และเวลา (เริ่มตั้งแต่ชั่วโมงถัดไปจนถึง 96 ชั่วโมง) ที่จะแสดงข้อมูลการพยากรณ์คุณภาพอากาศรายชั่วโมง

curl -X POST -d '{
  "location": {
    "latitude": 37.4125333,
    "longitude": -122.0840937
  },
  "dateTime": "2024-02-09T08:00:00Z"
}' \
-H "Content-Type: application/json" \
-H "Accept-Language: *" \
"https://airquality.googleapis.com/v1/forecast:lookup?key=YOUR_API_KEY"

การเรียกใช้จะสร้างการตอบสนอง JSON ต่อไปนี้

{
  "hourlyForecasts": [
    {
      "dateTime": "2024-02-09T08:00:00Z",
      "indexes": [
        {
          "code": "uaqi",
          "displayName": "Universal AQI",
          "aqi": 80,
          "aqiDisplay": "80",
          "color": {
            "red": 0.34509805,
            "green": 0.74509805,
            "blue": 0.20784314
          },
          "category": "Excellent air quality",
          "dominantPollutant": "pm25"
        }
      ]
    }
  ],
  "regionCode": "us"
}

ตัวอย่างคำขอที่มีพารามิเตอร์หลายรายการ

โค้ดต่อไปนี้แสดงวิธีสร้างเนื้อหาคำขอที่มีพารามิเตอร์หลายรายการ ในตัวอย่างนี้ คุณต้องระบุสิ่งต่อไปนี้

  • ตำแหน่ง
  • ระยะเวลาที่จะแสดงข้อมูลการพยากรณ์คุณภาพอากาศ
  • รหัสภาษา
  • การคำนวณเพิ่มเติม (เช่น คำแนะนำด้านสุขภาพ ความเข้มข้นของสารมลพิษหลัก และข้อมูลสารมลพิษเพิ่มเติม)
  • ชุดสี
curl -X POST -d '{
    "pageSize": "10",
    "universalAqi": "true",
    "location": {
        "latitude": "40.741895",
        "longitude": "-73.989308"
    },
    "period": {
        "startTime": "2024-02-27T13:58:14+02:00",
        "endTime": "2024-02-28T16:58:14+02:00"
    },
    "languageCode": "en",
    "extraComputations": [
        "HEALTH_RECOMMENDATIONS",
        "DOMINANT_POLLUTANT_CONCENTRATION",
        "POLLUTANT_ADDITIONAL_INFO"
    ],
    "uaqiColorPalette": "RED_GREEN"
}' \
-H "Content-Type: application/json" \
-H "Accept-Language: *" \
"https://airquality.googleapis.com/v1/forecast:lookup?key=YOUR_API_KEY"

การเรียกใช้จะสร้างการตอบสนอง JSON ต่อไปนี้

{
  {
  "hourlyForecasts": [
    {
      "dateTime": "2024-02-27T11:00:00Z",
      "indexes": [
        {
          "code": "uaqi",
          "displayName": "Universal AQI",
          "aqi": 75,
          "aqiDisplay": "75",
          "color": {
            "red": 0.43137255,
            "green": 0.7764706,
            "blue": 0.20392157
          },
          "category": "Good air quality",
          "dominantPollutant": "pm25"
        }
      ],
      "pollutants": [
        {
          "code": "pm25",
          "displayName": "PM2.5",
          "fullName": "Fine particulate matter (\u003c2.5µm)",
          "concentration": {
            "value": 15.1,
            "units": "MICROGRAMS_PER_CUBIC_METER"
          },
          "additionalInfo": {
            "sources": "...",
            "effects": "..."
          }
        }
      ],
      "healthRecommendations": {
        "generalPopulation": "...",
        "lungDiseasePopulation": "...",
        "heartDiseasePopulation": "...",
        "athletes": "...",
        "pregnantWomen": "..."
      }
    },
    {
      "dateTime": "2024-02-27T12:00:00Z",
      "indexes": [
        {
          "code": "uaqi",
          "displayName": "Universal AQI",
          "aqi": 67,
          "aqiDisplay": "67",
          "color": {
            "red": 0.5882353,
            "green": 0.8392157,
            "blue": 0.16862746
          },
          "category": "Good air quality",
          "dominantPollutant": "pm25"
        }
      ],
      "pollutants": [
        {
          "code": "pm25",
          "displayName": "PM2.5",
          "fullName": "Fine particulate matter (\u003c2.5µm)",
          "concentration": {
            "value": 19.96,
            "units": "MICROGRAMS_PER_CUBIC_METER"
          },
          "additionalInfo": {
            "sources": "...",
            "effects": "..."
          }
        }
      ],
      "healthRecommendations": {
        "generalPopulation": "...",
        "lungDiseasePopulation": "...",
        "heartDiseasePopulation": "...",
        "athletes": "...",
        "pregnantWomen": "...",
        "children": "..."
      }
    },
    /.../
  ]
  }
  "regionCode": "us",
  "nextPageToken": "CjMKEglwCFVq9l5EQBH0aoDSUH9SwBoQCgYI1pDirgYSBgiGiOiuBiABKgMCBAMyAmVuOAEQGA=="
}

หากต้องการดูข้อมูลการคาดการณ์หน้าถัดไป ให้ส่งใน nextPageToken ที่แสดงผลท้ายเนื้อหาการตอบกลับ

curl -X POST -d '{
    "universalAqi": "true",
    "location": {
        "latitude": "40.741895",
        "longitude": "-73.989308"
    },
    "period": {
        "startTime": "2024-02-27T13:58:14+02:00",
        "endTime": "2024-02-28T16:58:14+02:00"
    },
    "languageCode": "en",
    "extraComputations": [
        "HEALTH_RECOMMENDATIONS",
        "DOMINANT_POLLUTANT_CONCENTRATION",
        "POLLUTANT_ADDITIONAL_INFO"
    ],
    "uaqiColorPalette": "RED_GREEN",
    "pageToken": "CjMKEglwCFVq9l5EQBH0aoDSUH9SwBoQCgYI1pDirgYSBgiGiOiuBiABKgMCBAMyAmVuOAEQGA=="
}' \
-H "Content-Type: application/json" \
-H "Accept-Language: *" \
"https://airquality.googleapis.com/v1/forecast:lookup?key=YOUR_API_KEY"

คอลัมน์นี้จะแสดงหน้าถัดไปของข้อมูลการคาดการณ์

{
  "hourlyForecasts": [
    {
      "dateTime": "2024-02-27T21:00:00Z",
      "indexes": [
        {
          "code": "uaqi",
          "displayName": "Universal AQI",
          "aqi": 74,
          "aqiDisplay": "74",
          "color": {
            "red": 0.44705883,
            "green": 0.78431374,
            "blue": 0.2
          },
          "category": "Good air quality",
          "dominantPollutant": "o3"
        }
      ],
      "pollutants": [
        {
          "code": "o3",
          "displayName": "O3",
          "fullName": "Ozone",
          "concentration": {
            "value": 32.07,
            "units": "PARTS_PER_BILLION"
          },
          "additionalInfo": {
            "sources": "...",
            "effects": "..."
          }
        }
      ],
      "healthRecommendations": {
        "generalPopulation": "...",
        "elderly": "...",
        "lungDiseasePopulation": "...",
        "heartDiseasePopulation": "...",
        "athletes": "...",
        "pregnantWomen": "...",
        "children": "..."
      }
    },
    {
      "dateTime": "2024-02-27T22:00:00Z",
      "indexes": [
        {
          "code": "uaqi",
          "displayName": "Universal AQI",
          "aqi": 75,
          "aqiDisplay": "75",
          "color": {
            "red": 0.43137255,
            "green": 0.7764706,
            "blue": 0.20392157
          },
          "category": "Good air quality",
          "dominantPollutant": "o3"
        }
      ],
      "pollutants": [
        {
          "code": "o3",
          "displayName": "O3",
          "fullName": "Ozone",
          "concentration": {
            "value": 30.94,
            "units": "PARTS_PER_BILLION"
          },
          "additionalInfo": {
            "sources": "...",
            "effects": "..."
          }
        }
      ],
      "healthRecommendations": {
        "generalPopulation": "...",
        "lungDiseasePopulation": "...",
        "heartDiseasePopulation": "...",
        "athletes": "...",
        "pregnantWomen": "...",
        "children": "..."
      }
    },
    /.../
  ]
  "regionCode": "us"
}