getTimezoneInfoFromCoordinates static method
- required Coordinates coords,
- required DateTime time,
- bool accurateResult = false,
- required void onCompleteCallback(
- GemError error,
- TimezoneResult? result
Async gets timezone info based on a coordinate and a timestamp
Parameters
- IN coords The location from where to get the timezone result
- IN time The time for which offsets are calculated (UTC)
- IN accurateResult If left 'false' the result will be computed using the available offline resource. If 'true' an HTTP request will be performed for computing the result
- IN onCompleteCallback The callback which will be called when the operation completes.
- Will be called with GemError.success error and non-null result upon success.
- Will be called with GemError.internalAbort error and null result if the result parsing failed or server internal error occurred
Returns
- ProgressListener for the operation progress if the operation could be started, null otherwise
Throws
- An exception if it fails.
Implementation
static ProgressListener? getTimezoneInfoFromCoordinates({
required final Coordinates coords,
required final DateTime time,
final bool accurateResult = false,
required final void Function(
GemError error,
TimezoneResult? result,
) onCompleteCallback,
}) {
final TimezoneResult result = TimezoneResult.create();
final EventDrivenProgressListener listener = EventDrivenProgressListener();
GemKitPlatform.instance.registerEventHandler(listener.id, listener);
listener.registerOnCompleteWithDataCallback((
final int err,
final String hint,
final Map<dynamic, dynamic> json,
) {
GemKitPlatform.instance.unregisterEventHandler(listener.id);
if (err == 0) {
onCompleteCallback(GemErrorExtension.fromCode(err), result);
} else {
onCompleteCallback(
GemErrorExtension.fromCode(err),
null,
);
}
});
final OperationResult resultString = staticMethod(
'TimezoneService',
'getTimezoneInfoCoords',
args: <String, dynamic>{
'timezoneResult': result.pointerId,
'coords': coords,
'time': time.millisecondsSinceEpoch,
'progressListener': listener.id,
'accurateResult': accurateResult
},
);
final GemError errCode = GemErrorExtension.fromCode(resultString['result']);
if (errCode != GemError.success) {
onCompleteCallback(errCode, null);
return null;
}
return listener;
}