mapbox / mapbox-navigation-ios

Turn-by-turn navigation logic and UI in Swift on iOS
https://docs.mapbox.com/ios/navigation/
Other
860 stars 310 forks source link

[Bug]: Start Navigation with a custom route with more than 25/100 coordinates (up to 2000) #3491

Closed nastasiupta closed 2 years ago

nastasiupta commented 2 years ago

Mapbox Navigation SDK version

2.0.0-rc.5

Steps to reproduce

1) Create an array of coordinates (latitude, longitude) with over 100 elements. 2) Use Directions.shared.calculate & NavigationViewController to start a custom route. 3) I use Directions.shared.calculate with NavigationRouteOptions/RouteOptions and the issue as I see is that the array of locations must have maximum 25 locations or 100 locations.

let routeOptions = NavigationRouteOptions(coordinates: coordinates)
Directions.shared.calculate(routeOptions) { [weak self] (session, result) in
    LoadingIndicator.hide {
        switch result {
        case .failure(let error):
            UIAlertController.show(title: ErrorTitle.serverError.value, message: error.localizedDescription)
        case .success(let response):
            guard let strongSelf = self else {
                return
            }
            let containerViewController = UIViewController.instantiate(type: .navigationBottomView) as? ContainerViewController
            let routeOptions = NavigationRouteOptions(coordinates: coordinates)
            let navigationOptions = NavigationOptions()
            navigationOptions.bottomBanner = containerViewController
            let navigationViewController = NavigationViewController(for: response, routeIndex: 0, routeOptions: routeOptions)
            navigationViewController.modalPresentationStyle = .fullScreen
        .....

Expected behavior

Before using the SDK version 2.0, I could create a Route object and setup the NavigationViewController with that Route object. But right now as I see, to init NavigationViewController I have to provide RouteResponse but as I see there is no way to use Directions.shared.calculate/Directions.shared.calculateRoute with a custom array of locations with up to 2000 coordinates.

What is the correct aproach with the SDK 2.0 for what I need :-? ?

Thanks in advice.

Actual behavior

When I want to start the navigation with an array with over 25 locations etc, but I get this error: "The operation couldn't be completed. Too many coordinates; maximum number of coordinates is 25."

there is another way that I found to set up with 100 coordinates but it's still not enough to replicate the functionality we had in the previous version.

Is this a one-time issue or a repeatable issue?

repeatable

S2Ler commented 2 years ago

Hello @nastasiupta,

You can still create your own RouteResponse and provide it to NavigationViewController.

nastasiupta commented 2 years ago

@S2Ler can you be more specific please? :-? I need an example to create RouteResponse with a given array of CLLocationCoordinate2D

1ec5 commented 2 years ago

Use this initializer. Something like this:

RouteResponse(httpResponse: nil, identifier: nil, routes: routes, waypoints: waypoints, options: .route(options), credentials: DirectionsCredentials(accessToken: nil, host: nil))

3494 tracks updating the map matching guide to use this updated syntax.

nastasiupta commented 2 years ago

@1ec5 but I don't have the routes objects.. I have just an array of CLLocationCoordinate2D :)

1ec5 commented 2 years ago

Route also has an initializer. But note that it requires a lot more information than just the coordinates, such as the text for voice instructions. Consider using the Map Matching API to convert your coordinates into a proper route. The Map Matching API also limits the number of coordinates to use. If you need more help using this workflow or need the limit to be increased, please contact the Mapbox Support team.

AlexanderCollins commented 2 years ago

@nastasiupta did you (or anyone else for that matter) come up with a solution (a code example perhaps) to share? It would be really helpful - I'm facing this same limitation.

AlexanderCollins commented 2 years ago

For those who come across the 25-waypoint limitation, I have made an implementation in my company's public fork of the most common react native wrapper for this repo.

Our solution was to make as many requests to the Mapbox Directions API as was needed and then combine the responses into a single route response to be passed to the MapboxNavigationService. This could be a good start for your own solution.

the implementation is in swift; https://github.com/drive-app/react-native-mapbox-navigation/commit/80333b2048276e82ce028a2722eec63f445278e6