startNavigation static method

TaskHandler? startNavigation(
  1. Route route,
  2. @Deprecated('Use onNavigationInstruction, onDestinationReached and onError instead') void onNavigationInstructionUpdate(
    1. NavigationEventType eventType,
    2. NavigationInstruction? instruction
    )?, {
  3. void onNavigationInstruction(
    1. NavigationInstruction instruction,
    2. Set<NavigationInstructionUpdateEvents> events
    )?,
  4. void onNavigationStarted()?,
  5. void onTextToSpeechInstruction(
    1. String textInstruction
    )?,
  6. void onWaypointReached(
    1. Landmark landmark
    )?,
  7. void onDestinationReached(
    1. Landmark landmark
    )?,
  8. void onRouteUpdated(
    1. Route route
    )?,
  9. void onBetterRouteDetected(
    1. Route route,
    2. int travelTime,
    3. int delay,
    4. int timeGain,
    )?,
  10. void onBetterRouteRejected(
    1. GemError reason
    )?,
  11. void onBetterRouteInvalidated()?,
  12. void onSkipNextIntermediateDestinationDetected()?,
  13. void onError(
    1. GemError error
    )?,
  14. void onNotifyStatusChange(
    1. NavigationStatus status
    )?,
})

Start a new navigation

Parameters

  • IN route Route to use for the navigation.

  • IN onNavigationInstructionUpdate Callback for navigation-specific events.

  • IN onNavigationInstruction Callback called when the navigation instruction is updated. This callback also sends turn update events.

  • 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.

    • route Route The newly detected better route.
    • travelTime int The travel time of the new route in seconds.
    • delay int Better route delay in seconds
    • timeGain int Time gain from the existing route in seconds. -1 means the original route has roadblocks and time gain cannot be calculated.
  • IN onBetterRouteRejected Better route rejected with given error code ( debug purposes )

  • 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.

  • IN onNotifyStatusChange Callback to notify UI if the navigation status has changed.

  • 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);
}