天气时光机

平台: API iOS Android

获取最近10天的天气历史再分析数据。

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

和风天气额外提供了2000年至今的历史再分析气象数据,通过数据文件的形式发送,如需要长时间的历史气象数据数据,请提供下列信息,发送邮件至sales@qweather.com,我们将有专人与你联系:

  • 企业名称
  • 联系方式
  • 所需要的城市或坐标
  • 所需要的时间范围
接口代码 接口 数据类
historicalWeather 历史天气 HistoricalWeatherResponse

参数

HistoricalWeatherParameter

  • location(必选)需要查询的地区,仅支持LocationID,LocationID可通过GeoAPI获取。例如 location=101010100
  • date(必选)选择日期,最多可选择最近10天(不包含今天)的数据。日期格式为yyyyMMdd,例如 date=20200531
  • lang多语言设置,请阅读多语言文档,了解我们的多语言是如何工作、如何设置以及数据是否支持多语言。
  • unit数据单位设置,可选值包括unit=m(公制单位,默认)和unit=i(英制单位)。更多选项和说明参考度量衡单位

示例代码

Swift

Task{
    do {
        let threeDaysAgo = Calendar.current.date(byAdding: .day, value: -3, to: Date())!
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyyMMdd"
        let date = formatter.string(from: threeDaysAgo)
        let parameter = HistoricalWeatherParameter(location: "101010100", date: date)
        let response = try await QWeather.instance
            .historicalWeather(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];
HistoricalWeatherParameter *parameter = [HistoricalWeatherParameter instanceWithLocation:@"101010100" date:date lang:@(LangZH_HANS) unit:@(UnitMETRIC)];
[QWeatherObjc historicalWeather:parameter completionHandler:^(HistoricalWeatherResponse * _Nullable response, NSError * _Nullable error) {
    if (response) {
        NSLog(@"%@", response.description);
    }
    if (error) {
        NSLog(@"%@", error.localizedDescription);
    }
}];

返回数据

HistoricalWeatherResponse

  • code 请参考状态码
  • fxLink 当前数据的响应式页面,便于嵌入网站或应用
  • weatherDaily.date 当天日期
  • weatherDaily.sunrise 当天日出时间在高纬度地区可能为空
  • weatherDaily.sunset 日落时间在高纬度地区可能为空
  • weatherDaily.moonrise 当天月升时间可能为空
  • weatherDaily.moonset 当天月落时间可能为空
  • weatherDaily.moonPhase 当天月相名称
  • weatherDaily.tempMax 当天最高温度
  • weatherDaily.tempMin 当天最低温度
  • weatherDaily.precip 当天总降水量,默认单位:毫米
  • weatherDaily.pressure 大气压强,默认单位:百帕
  • weatherDaily.humidity 当天每小时相对湿度,百分比数值
  • weatherHourly.time 当天时间
  • weatherHourly.temp 当天每小时温度,默认单位:摄氏度
  • weatherHourly.icon 当天每小时天气状况的图标代码,另请参考天气图标项目
  • weatherHourly.text 当天每小时天气状况的文字描述,包括阴晴雨雪等天气状态的描述
  • weatherHourly.wind360 当天每小时风向360角度
  • weatherHourly.windDir 当天每小时风向
  • weatherHourly.windScale 当天每小时风力等级
  • weatherHourly.windSpeed 当天每小时风速,公里/小时
  • weatherHourly.humidity 当天每小时相对湿度,百分比数值
  • weatherHourly.precip 当天每小时累计降水量,默认单位:毫米
  • weatherHourly.pressure 大气压强,默认单位:百帕
  • refer.sources 原始数据来源,或数据源说明,可能为空
  • refer.license 数据许可或版权声明,可能为空