startNavigation static method
Start a new navigation
Parameters
-
IN route Route to use for the navigation.
-
IN onNavigationInstructionUpdate Callback for navigation-specific events.
- eventType NavigationEventType The type of navigation event.
- instruction NavigationInstruction? The navigation instruction, if any.
-
IN onNavigationInstruction Callback called when the navigation instruction is updated. This callback also sends turn update events.
- instruction NavigationInstruction The updated navigation instruction
- events Set<NavigationInstructionUpdateEvents> The events that triggered the update
-
IN onTextToSpeechInstruction Callback called when a sound needs to be played.
- textInstruction String The instruction text to be spoken.
-
IN onWaypointReached Callback called when a waypoint on the route has been reached. This callback is not called when the destination of the route has been reached. That is notified through
onDestinationReached
notification.- landmark Landmark The landmark that was reached.
-
IN onDestinationReached Callback called when the destination has been reached. This is the moment when the navigation request finished with success.
- landmark Landmark The landmark that was reached.
-
IN onRouteUpdated Callback called when route was updated.
- route Route The updated route.
-
IN onBetterRouteDetected Better route was detected. The previous better route ( if it exists ) must be considered automatically invalidated. This callback is called when a route is calculated with 'avoid traffic' flag set to 'true' (RoutePreferences.avoidTraffic) and the engine detects a better route.
-
IN onBetterRouteRejected Better route rejected with given error code ( debug purposes )
- errorCode GemError Rejection reason
-
IN onBetterRouteInvalidated Previously detected better route became invalid. This callback is called when current position is no longer on the previously calculated better route
-
IN onError Callback called when an error occurs.
- error GemError The error code.
-
IN onNotifyStatusChange Callback to notify UI if the navigation status has changed.
- status NavigationStatus The navigation status.
-
IN onSkipNextIntermediateDestinationDetected Next intermediate destination skip intention detected. This notification is sent the navigation engine detects user intention to skip the next intermediate destination
-
IN onNavigationStarted Navigation started callback. This callback is called when first valid position for navigation arrives
Throws
- An exception if it fails.
Implementation
static TaskHandler? startNavigation(
final Route route,
@Deprecated(
'Use onNavigationInstruction, onDestinationReached and onError instead',
)
final void Function(
NavigationEventType eventType,
NavigationInstruction? instruction,
)? onNavigationInstructionUpdate, {
final void Function(
NavigationInstruction instruction,
Set<NavigationInstructionUpdateEvents> events,
)? onNavigationInstruction,
final void Function()? onNavigationStarted,
final void Function(String textInstruction)? onTextToSpeechInstruction,
final void Function(Landmark landmark)? onWaypointReached,
final void Function(Landmark landmark)? onDestinationReached,
final void Function(Route route)? onRouteUpdated,
final void Function(Route route, int travelTime, int delay, int timeGain)?
onBetterRouteDetected,
final void Function(GemError reason)? onBetterRouteRejected,
final void Function()? onBetterRouteInvalidated,
final void Function()? onSkipNextIntermediateDestinationDetected,
final void Function(GemError error)? onError,
final void Function(NavigationStatus status)? onNotifyStatusChange,
}) {
final OperationResult result = staticMethod(
'NavigationService',
'startNavigation',
args: <String, dynamic>{'route': route.pointerId, 'simulation': false},
);
final int gemApiError = result['gemApiError'];
if (GemErrorExtension.isErrorCode(gemApiError)) {
final GemError errorCode = GemErrorExtension.fromCode(gemApiError);
onError?.call(errorCode);
return null;
}
final int listenerId = result['result'];
final NavigationListener listener = NavigationListener.init(listenerId);
listener.registerAll(
onNavigationStarted: onNavigationStarted,
onNavigationInstructionUpdated: (
final NavigationInstruction instruction,
final Set<NavigationInstructionUpdateEvents> events,
) {
onNavigationInstructionUpdate?.call(
NavigationEventType.navigationInstructionUpdate,
instruction,
);
onNavigationInstruction?.call(instruction, events);
},
onWaypointReached: onWaypointReached,
onDestinationReached: (final Landmark destination) {
onNavigationInstructionUpdate?.call(
NavigationEventType.destinationReached,
null,
);
onDestinationReached?.call(destination);
},
onNavigationError: (final GemError error) {
GemKitPlatform.instance.unregisterEventHandler(listener.id);
onNavigationInstructionUpdate?.call(NavigationEventType.error, null);
onError?.call(error);
},
onRouteUpdated: onRouteUpdated,
onNavigationSound: onTextToSpeechInstruction,
onNotifyStatusChange: onNotifyStatusChange,
onBetterRouteDetected: onBetterRouteDetected,
onBetterRouteRejected: onBetterRouteRejected,
onBetterRouteInvalidated: onBetterRouteInvalidated,
onSkipNextIntermediateDestinationDetected:
onSkipNextIntermediateDestinationDetected,
);
GemKitPlatform.instance.registerEventHandler(listener.id, listener);
return TaskHandlerImpl(listener.id);
}