Time Machine for Air Quality

Platform: API iOS Android

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

  • code See Status Code
  • fxLink Responsive web page of this data, for embedded in website or APP
  • airHourly.pubTime The data release time from the data source
  • airHourly.aqi Air Quality Index
  • airHourly.level AQI level
  • airHourly.category AQI category
  • airHourly.primary The main pollutant. If level=1, return NA
  • airHourly.pm10 PM10
  • airHourly.pm2p5 PM2.5
  • airHourly.no2 Nitrogen dioxide
  • airHourly.so2 Sulfur dioxide
  • airHourly.co Carbon monoxide
  • airHourly.o3 Ozone
  • refer.sources Data source and other statements, may be null
  • refer.license Data license, may be null