Time Machine for Air Quality
Get the last 10 days of air quality history data.
Let’s say, today is December 30, you can get data from Dec. 20 to Dec. 29.
| Interface code | Interface | Class |
|---|---|---|
| historicalAir | Historical air quality | HistoricalAirResponse |
Parameters
HistoricalAirParameter
-
location(required)The location to be queried, only support LocationID and LocationID can be obtained by GeoAPI. For example:location=101010100 -
date(required)Set the date, up to the most recent 10 days. The date format is yyyyMMdd. Example:date=20200531 -
langMulti-language setting, please see Language to find out how our multi-language works and how to set up.
Sample code
Swift
Task{
do {
let threeDaysAgo = Calendar.current.date(byAdding: .day, value: -3, to: Date())!
let formatter = DateFormatter()
formatter.dateFormat = "yyyMMdd"
let date = formatter.string(from: threeDaysAgo)
let parameter = HistoricalAirParameter(location: "101010100", date: date)
let response = try await QWeather.instance
.historicalAir(parameter)
print(response)
} catch QWeatherError.errorResponse(let error) {
print(error)
} catch {
print(error)
}
}
Objective-C
NSDate * threeDaysAgo = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitDay value:-3 toDate:[NSDate date] options:0];
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyyMMdd"];
NSString * date = [formatter stringFromDate:threeDaysAgo];
HistoricalAirParameter *parameter = [HistoricalAirParameter instanceWithLocation:@"101010100" date:date lang:@(LangZH_HANS)];
[QWeatherObjc historicalAir:parameter completionHandler:^(HistoricalAirResponse * _Nullable response, NSError * _Nullable error) {
if (response) {
NSLog(@"%@", response.description);
}
if (error) {
NSLog(@"%@", error.localizedDescription);
}
}];
Response
HistoricalAirResponse
-
codeSee Status Code -
fxLinkResponsive web page of this data, for embedded in website or APP -
airHourly.pubTimeThe data release time from the data source -
airHourly.aqiAir Quality Index -
airHourly.levelAQI level -
airHourly.categoryAQI category -
airHourly.primaryThe main pollutant. Iflevel=1, returnNA -
airHourly.pm10PM10 -
airHourly.pm2p5PM2.5 -
airHourly.no2Nitrogen dioxide -
airHourly.so2Sulfur dioxide -
airHourly.coCarbon monoxide -
airHourly.o3Ozone -
refer.sourcesData source and other statements, may be null -
refer.licenseData license, may be null