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
RouteReplanningEngineto perform route replanning based on theNavigationSnapshotof the current navigation session. The RouteReplanningEngine determines the timing and method selection for the RouteReplanner to call. The Navigation SDK providesRouteReplannerFactoryto create instances of the RouteReplanner for the selected mode, andHybridRouteReplannerimplementation 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
Routeinformation asynchronously.Declaration
Swift
func update(_ options: RouteUpdateOptions) -> AsyncThrowingStream<Route, Error>Parameters
optionsThe options used to request a route update.
Return Value
An
AsyncThrowingStreamthat providesRouteobjects when successful or throws anErrorif 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
optionsOptions for back to route planning.
Return Value
An
AsyncThrowingStreamthat providesRouteobjects when successful or throws anErrorif something goes wrong. -
advanceGuidanceProgress(_:Asynchronous) 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
RouteReplanningReasonincrement.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 -> RouteParameters
optionsParameters for a route replan.
Return Value
A
Routeobject.
TomTom SDK for iOS (0.71.1)
RouteReplanner