Not getting much help from Mapbox people, wondering if someone else has had this issue. I am trying to display an array of routes on Mapbox. I used to use the method NavigationMap.show([route1, route2])
but now it is navigationMapView.show(<#T##navigationRoutes: NavigationRoutes##NavigationRoutes#>, routeAnnotationKinds: <#T##Set<RouteAnnotationKind>#>)
.
The updated method now takes NavigationRoutes instead of an array of routes. NavigationRoutes contains a main route and alternate routes to the same destination. However I need to display two routes to two different destinations.
I am generating the route like so:
let userWaypoint = Waypoint(
location: CLLocation(latitude: location.latitude, longitude: location.longitude),
name: "user"
)
let destinationWaypoint = Waypoint(coordinate: CLLocationCoordinate2D(latitude: destination.latitude, longitude: destination.longitude))
let navigationRouteOptions = NavigationRouteOptions(waypoints: [userWaypoint, destinationWaypoint])
let task = mapboxNavigation.routingProvider().calculateRoutes(options: navigationRouteOptions)
Task { [weak self] in
switch await task.result {
case .failure(let error):
print(error.localizedDescription)
case .success(let response):
guard let self else { return }
// I used to add the new route to an array and then show the routes
// but this no longer works
//routes.append(response.mainRoute)
//navigationMapView.show(routes)
navigationRoutes = response
}
}
And then like in the mapbox tutorial:
var navigationRoutes: NavigationRoutes? {
didSet {
showCurrentRoute()
}
}
func showCurrentRoute() {
guard let navigationRoutes else {
return
}
navigationMapView.showcase(navigationRoutes)
}
Every time showcase
is called, removeRoutes()
is also called so I can not show multiple navigationRoutes
. Anyone have a solution to this or do I need to edit the mapbox method?