ปลายทางการคาดการณ์จะให้ข้อมูลการคาดการณ์คุณภาพอากาศรายชั่วโมงสำหรับสถานที่นั้นๆ สูงสุด 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" }