RouteReplanner

public protocol RouteReplanner

Provides dynamic route replanning capabilities by updating routes, handling deviations, and incrementally updating route guidance.

Overview

The RouteReplanner API enables dynamic route replanning during navigation. By integrating this API, developers can:

  • Update routes in real-time
  • Manage route deviations
  • Incrementally guide users with updated instructions and lane guidance. The RouteReplanner is used by the RouteReplanningEngine to perform route replanning based on the NavigationSnapshot of the current navigation session. The RouteReplanningEngine determines the timing and method selection for the RouteReplanner to call. The Navigation SDK provides RouteReplannerFactory to create instances of the RouteReplanner for the selected mode, and HybridRouteReplanner implementation for hybrid mode.

Code Snippets

Example: Refreshing a Route

let updateOptions = RouteUpdateOptions(...) // Configure your route update options
let routeStream = routeReplanner.update(updateOptions)
for try await route in routeStream {
    // Handle updated route
}

Example: Handling Route Deviations

let deviationOptions = BackToRouteOptions(...) // Configure your deviation options
let deviationStream = routeReplanner.backToRoute(deviationOptions)
for try await route in deviationStream {
    // Handle deviation update
}
Example: Incremental Route Guidance
let incrementOptions = RouteIncrementOptions(...) // Configure your increment options
let updatedRoute = try await routeReplanner.advanceGuidanceProgress(incrementOptions)
// Use the updated route

Threading Requirements

The methods in RouteReplanner are designed to be called from asynchronous contexts. The methods provided by the RouteReplanner should be called on a background thread as they involve time-consuming operations, such as network requests and offline route computation.

Important

This is a Public Preview API. It may be changed or removed at any time.
  • Refreshes the current route based on the provided options.

    Use this method to get updated Route information asynchronously.

    Declaration

    Swift

    func update(_ options: RouteUpdateOptions) -> AsyncThrowingStream<Route, Error>

    Parameters

    options

    The options used to request a route update.

    Return Value

    An AsyncThrowingStream that provides Route objects when successful or throws an Error if something goes wrong.

  • Replans the route each time a deviation occurs.

    This method helps you get back on track by providing updated routing information asynchronously.

    Declaration

    Swift

    func backToRoute(_ options: BackToRouteOptions) -> AsyncThrowingStream<Route, Error>

    Parameters

    options

    Options for back to route planning.

    Return Value

    An AsyncThrowingStream that provides Route objects when successful or throws an Error if something goes wrong.

  • If the current route guidance is incomplete, supplement the route with more guidance.

    This method is useful for incrementally updating route instructions and lane guidance. May result in RouteReplanningReason increment.

    Throws

    An error if the operation is cancelled or if other issues occur during the replan process.

    Declaration

    Swift

    func advanceGuidanceProgress(_ options: RouteIncrementOptions) async throws -> Route

    Parameters

    options

    Parameters for a route replan.

    Return Value

    A Route object.