getSunriseAndSunset static method

Pair<DateTime, DateTime> getSunriseAndSunset(
  1. Coordinates coords,
  2. DateTime time
)

Get the sunrise & sunset for the specified reference date and WGS position.

If no time is provided then the device time is used.

The sunset may happen next day or even later (close to poles). Returned value is UTC. The sunrise may happen in the same day or before (close to poles). Returned value is UTC.

Parameters

Returns

  • A pair with sunrise and sunset, first is sunrise, second is sunset, both as DateTime

Throws

  • An exception if it fails.

Implementation

static Pair<DateTime, DateTime> getSunriseAndSunset(
  final Coordinates coords,
  final DateTime time,
) {
  final OperationResult resultString = objectMethod(
    0,
    'MapDetails',
    'getSunriseAndSunset',
    args: <String, Object>{
      'coords': coords,
      'refTime': time.millisecondsSinceEpoch,
    },
  );

  final Map<String, dynamic> result =
      resultString['result'] as Map<String, dynamic>;
  final int first = result['first'];
  final int second = result['second'];

  return Pair<DateTime, DateTime>(
    DateTime.fromMillisecondsSinceEpoch(first, isUtc: true),
    DateTime.fromMillisecondsSinceEpoch(second, isUtc: true),
  );
}