Bring your own route
Dynamically update and adjust selected routes based on user preferences and real-time conditions.
This example shows:
-
How to customize your RoutingProvider for NBNavigationSerivce
-
How to simulate your routing Progress with customized NavigatinOptions
For all code examples, refer to Navigation Code Examples
CustomRouteNavigationController view source
The code above creates a simple custom routing app using NbmapNavigation libraries. It consists of two classes: CustomRouteNavigationController and CustomRoutingProvider.
The CustomRouteNavigationController class is the main view controller that sets up the navigation:
-
It sets the origin and destination coordinates for the route.
-
It creates a NavigationRouteOptions object using the origin and destination.
-
It initializes a CustomRoutingProvider to provide custom routing services.
-
It calls the calculateRoutes function from the custom routing provider, passing the options and a completion handler.
-
When a route is received in the completion handler, it initializes a NBNavigationService with the calculated routes and settings.
-
It creates a NavigationOptions object with the navigationService.
-
It initializes a NavigationViewController and presents it.
The CustomRoutingProvider class is a custom implementation of the RoutingProvider protocol that uses NbmapDirections to calculate routes:
-
It implements the calculateRoutes function that takes a RouteOptions object and a completion handler.
-
It calls the calculate function from Directions.shared and returns a CustomRequest object with the URLSessionDataTask object.