历史空气质量

平台: API iOS Android

获取最近10天的中国空气质量历史再分析数据。

例如今天是12月30日,最多可获取12月20日至12月29日的空气质量历史数据。

接口代码 接口 数据类
historicalAir 历史空气质量 HistoricalAirResponse

参数

HistoricalAirParameter

  • location(必选)需要查询的地区,仅支持LocationID,LocationID可通过GeoAPI获取。例如 location=101010100
  • date(必选)选择日期,最多可选择最近10天(不包含今天)的数据。日期格式为yyyyMMdd,例如 date=20200531
  • lang多语言设置,请阅读多语言文档,了解我们的多语言是如何工作、如何设置以及数据是否支持多语言。

示例代码

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);
    }
}];

返回数据

HistoricalAirResponse

  • code 请参考状态码
  • fxLink 当前数据的响应式页面,便于嵌入网站或应用
  • airHourly.pubTime 空气质量数据发布时间
  • airHourly.aqi 空气质量指数
  • airHourly.level 空气质量指数等级
  • airHourly.category 空气质量指数级别
  • airHourly.primary 空气质量的主要污染物,空气质量为优时,返回值为NA
  • airHourly.pm10 PM10
  • airHourly.pm2p5 PM2.5
  • airHourly.no2 二氧化氮
  • airHourly.so2 二氧化硫
  • airHourly.co 一氧化碳
  • airHourly.o3 臭氧
  • refer.sources 原始数据来源,或数据源说明,可能为空
  • refer.license 数据许可或版权声明,可能为空