initializeNavigationSession static method

Future<void> initializeNavigationSession({
  1. bool abnormalTerminationReportingEnabled = true,
  2. TaskRemovedBehavior taskRemovedBehavior = TaskRemovedBehavior.continueService,
})

Initializes the navigation session.

Successful initialization requires that a valid Maps API key has been defined, and the user has accepted the navigation terms and conditions and granted location permissions for the app. Otherwise the method throws SessionInitializationException.

Before the initialization different navigation actions provided by GoogleMapsNavigator (GoogleMapsNavigator.setDestinations, GoogleMapsNavigator.startGuidance, etc.) throw SessionNotInitializedException.

Checks if there are active listeners for either road-snapped location updates or raw location updates. If there are, this method re-enables the emission of road-snapped location updates. This is necessary because the native (Android/iOS) implementation clears the listeners during cleanup.

Optional parameter abnormalTerminationReportingEnabled can be used enables/disables reporting abnormal SDK terminations such as the app crashes while the SDK is still running.

Implementation

static Future<void> initializeNavigationSession({
  bool abnormalTerminationReportingEnabled = true,
  TaskRemovedBehavior taskRemovedBehavior =
      TaskRemovedBehavior.continueService,
}) async {
  await GoogleMapsNavigationPlatform.instance.navigationSessionAPI
      .createNavigationSession(
        abnormalTerminationReportingEnabled,
        taskRemovedBehavior,
      );

  // Enable road-snapped location updates if there are subscriptions to them.
  if ((_roadSnappedLocationUpdatedController?.hasListener ?? false) ||
      (_roadSnappedRawLocationUpdatedController?.hasListener ?? false) ||
      (_gpsAvailabilityUpdatedController?.hasListener ?? false) ||
      (_gpsAvailabilityChangeController?.hasListener ?? false)) {
    await GoogleMapsNavigationPlatform.instance.navigationSessionAPI
        .enableRoadSnappedLocationUpdates();
  }
}