ปลายทาง forecast จะให้ข้อมูลพยากรณ์คุณภาพอากาศรายชั่วโมงสูงสุด 96 ชั่วโมง (4 วัน) สำหรับสถานที่ที่ระบุ การพยากรณ์แต่ละครั้งจะรวมดัชนีคุณภาพอากาศรายชั่วโมง รวมถึงข้อมูลเพิ่มเติมดังนี้
- เวลาและวันที่หรือระยะเวลาที่เฉพาะเจาะจงสำหรับการพยากรณ์
- รหัสภาษาสำหรับช่องที่แปล
- ดัชนีคุณภาพอากาศ (AQI) ในพื้นที่หรือแบบกำหนดเอง
- คำแนะนำด้านสุขภาพ
- สารมลพิษหลัก
- ความเข้มข้นของสารมลพิษ
- ข้อมูลเพิ่มเติมเกี่ยวกับสารมลพิษ
- ขนาดหน้าการตอบกลับ
- ชุดสี
โปรแกรมสำรวจ API ช่วยให้คุณส่งคำขอแบบสดๆ เพื่อให้คุ้นเคยกับ API และตัวเลือก API
เกี่ยวกับคำขอพยากรณ์
คุณสามารถขอข้อมูลพยากรณ์คุณภาพอากาศรายชั่วโมงได้โดยใช้ปลายทางการพยากรณ์ด้วยการส่งคำขอ 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" }
ลองใช้งาน
โปรแกรมสำรวจ API ช่วยให้คุณส่งคำขอตัวอย่างเพื่อให้คุ้นเคยกับ API และตัวเลือก API
เลือกไอคอน API api ทางด้านขวาของหน้า
แก้ไขพารามิเตอร์คำขอ (ไม่บังคับ)
เลือกปุ่มเรียกใช้ ในกล่องโต้ตอบ ให้เลือกบัญชี ที่ต้องการใช้ส่งคำขอ
ในแผงโปรแกรมสำรวจ API ให้เลือกไอคอนเต็มหน้าจอ fullscreen เพื่อขยายหน้าต่างโปรแกรมสำรวจ API