日出日落
获取未来60天全球任意地点日出日落时间。
在逐天预报API中,也会返回对应天数的日出日落、月升月落和月相数据
接口代码 | 接口 | 数据类 |
---|---|---|
astronomySun | 日出日落 | AstronomySunResponse |
参数
AstronomySunParameter
-
location
(必选)需要查询地区的LocationID或以英文逗号分隔的经度,纬度坐标(十进制,最多支持小数点后两位),LocationID可通过GeoAPI获取。例如location=101010100
或location=116.41,39.92
-
date
(必选)选择日期,最多可选择未来60天(包含今天)的数据。日期格式为yyyyMMdd,例如date=20200531
示例代码
Swift
Task {
do {
let formatter = DateFormatter()
formatter.dateFormat = "yyyMMdd"
let date = formatter.string(from: Date())
let parameter = AstronomySunParameter(location: "101010100", date: date)
let response = try await QWeather.instance
.astronomySun(parameter)
print(response)
} catch QWeatherError.errorResponse(let error) {
print(error)
} catch {
print(error)
}
}
Objective-C
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyyMMdd"];
NSString * date = [formatter stringFromDate:[NSDate date]];
AstronomySunParameter *parameter = [AstronomySunParameter instanceWithLocation:@"101010100" date:date];
[QWeatherObjc astronomySun:parameter completionHandler:^(AstronomySunResponse * _Nullable response, NSError * _Nullable error) {
if (response) {
NSLog(@"%@", response.description);
}
if (error) {
NSLog(@"%@", error.localizedDescription);
}
}];
返回数据
AstronomySunResponse
-
code
请参考状态码 -
updateTime
当前API的最近更新时间 -
fxLink
当前数据的响应式页面,便于嵌入网站或应用 -
sunrise
日出时间,在高纬度地区可能为空 -
sunset
日落时间,在高纬度地区可能为空 -
refer.sources
原始数据来源,或数据源说明,可能为空 -
refer.license
数据许可或版权声明,可能为空