mapbox / mapbox-navigation-ios

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

[Bug]: Cannot select alternative route in v3.0.2 #4657

Closed fbeccaceci closed 6 months ago

fbeccaceci commented 6 months ago

Mapbox Navigation SDK version

3.0.2

Steps to reproduce

This is all the code i have for a navigation view inside my app

public class EMBNavigationView: UIView {

    let navigationProvider = MapboxNavigationProvider.shared
    let navigationMapView: NavigationMapView

    let locationProvider = {
        let provider = AppleLocationProvider()
        provider.options.activityType = .automotiveNavigation
        return provider
    }()

    private var preloadedRoutes: NavigationRoutes?

    public required init() {
        let navigation = navigationProvider.navigation()

        self.navigationMapView = NavigationMapView(
            location: navigation.locationMatching.map(\.location).eraseToAnyPublisher(),
            routeProgress: navigation.routeProgress.map(\.?.routeProgress).eraseToAnyPublisher(),
            heading: navigation.heading,
            predictiveCacheManager: navigationProvider.predictiveCacheManager
        )

        super.init()

        setupNavigationMapView()
    }

    private func setupNavigationMapView() {
        navigationMapView.delegate = self

        navigationMapView.mapView.ornaments.options.compass.visibility = .visible
        navigationMapView.mapView.ornaments.attributionButton.layer.opacity = 0

        navigationMapView.mapView.location.options.puckType = .puck2D(.makeDefault(showBearing: true))
        navigationMapView.mapView.location.options.puckBearing = .heading
        navigationMapView.mapView.location.options.puckBearingEnabled = true

        navigationMapView.mapView.location.override(provider: locationProvider)

        navigationMapView.mapViewTapGestureRecognizer.addTarget(self, action: #selector(testStuff))

        addSubview(navigationMapView)

        navigationMapView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }

    func preloadRoutes(to target: CLLocationCoordinate2D) async {
        let mapboxNavigation = navigationProvider.mapboxNavigation
        let routingProvider = mapboxNavigation.routingProvider()

        guard let userLocation = navigationMapView.mapView.location.latestLocation else {
            return
        }

        let coordinates = [
            userLocation.coordinate,
            target
        ]
        let options = NavigationRouteOptions(coordinates: coordinates)

        let routes = try! await routingProvider.calculateRoutes(options: options).value

        self.preloadedRoutes = routes
    }

    func showPreloadedRoutes() {
        guard let routes = self.preloadedRoutes else { return }

        navigationMapView.showcase(routes, routesPresentationStyle: .all(shouldFit: true))
    }

    func removeRoutes() {
        navigationMapView.removeRoutes()
    }

}

After calling navigationMapView.showcase() i can correctly see 2 routes on the map, the problem is that i cannot select the alternative route, if i click on the route nothing happens on the screen and i get this log:

[Warning, navigation-ios/navigation]: Unable to access an alternative route at index

Expected behavior

The alternative route becomes selected

Actual behavior

Nothing happens on the screen and i get a warning log

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

repeatable