Solar Elevation Angle

Platform: API iOS Android

Get global solar elevation angle and azimuth.

Interface code Interface Class
astronomySolarElevationAngle Solar elevation angle data AstronomySolarElevationAngleResponse

Parameters

SolarElevationAngleParameter

  • location(required)The comma-separated longitude and latitude (decimal, up to 2 decimal places) of the location to be queried. For example: location=116.41,39.92
  • date(required)Set date, format is yyyyMMdd, e.g., date=20200531
  • time(required)Set time, format is HHmm, 24-hour, e.g., time=1230
  • tz(required)Location time zone, e.g., tz=0800 or tz=-0530
  • alt(required)Location altitude, in meters, e.g., alt=43

Sample code

Swift

Task {
    do {
        let currentDate = Date()
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyMMdd"
        let date = dateFormatter.string(from: currentDate)
        
        let timeFormatter = DateFormatter()
        timeFormatter.dateFormat = "HHmm"
        timeFormatter.locale = Locale(identifier: "en_US_POSIX")
        let time = timeFormatter.string(from: currentDate)
        
        let parameter = SolarElevationAngleParameter(location: "101010100", date: date, time: time, tz: "0800", alt: "43")
        let response = try await QWeather.instance
            .astronomySolarElevationAngle(parameter)
        print(response)
    } catch QWeatherError.errorResponse(let error) {
        print(error)
    } catch {
        print(error)
    }
}

Objective-C

NSDate * current = [NSDate date];
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyyMMdd"];
NSString * date = [formatter stringFromDate:current];

NSDateFormatter * timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:@"yyyyMMdd"];
[timeFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];
NSString * time = [formatter stringFromDate:current];

SolarElevationAngleParameter *parameter = [SolarElevationAngleParameter instanceWithLocation:@"116.41,39.92" date:date time:time tz:@"0800" alt:@"43"];

[QWeatherObjc astronomySolarElevationAngle:parameter completionHandler:^(AstronomySolarElevationAngleResponse * _Nullable response, NSError * _Nullable error) {
    if (response) {
        NSLog(@"%@", response.description);
    }
    if (error) {
        NSLog(@"%@", error.localizedDescription);
    }
}];

Response

AstronomySolarElevationAngleResponse

  • code See Status Code
  • solarElevationAngle Solar Elevation Angle in degree
  • solarAzimuthAngle Solar azimuth angle
  • solarHour Solar time, HHmm format
  • hourAngle Hour Angle
  • refer.sources Data source and other statements, may be null
  • refer.license Data license, may be null