iOS中的Mapbox导航与我的mapView控制器一起使用

Aak*_*ani 6 navigation ios mapbox swift mapbox-ios

我想将Mapbox导航集成到iOS中,我可以轻松获取两个坐标之间的方向/路线,也可以从Mapbox获取导航路径,我们可以使用以下代码

let options = NavigationOptions(styles: nil)
let viewController = NavigationViewController(for: self.directionsRoute!)
viewController.delegate=self    
self.present(viewController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

但是问题是我想在另一个视图控制器一部分的mapview中显示导航,我可以通过获取方向/路线和指令来做到这一点,但是找不到任何每秒都会被调用的方法,因此如果用户更改路径,我可以更新路径指令以及路径。

让我知道我是否遗漏任何东西或需要任何更改。

-提前致谢

cld*_*drr 0

也许这会有所帮助:您可以轻松添加路线进度变化的观察者:

NotificationCenter.default.addObserver(self,
                                       selector: #selector(progressDidChange(notification:)),
                                       name: .routeControllerProgressDidChange,
                                       object: navigationService.router)
Run Code Online (Sandbox Code Playgroud)

您需要通过创建路线来提供导航服务,例如

let navigationService = MapboxNavigationService(route: route)
Run Code Online (Sandbox Code Playgroud)

该函数progressDidChange可以执行以下操作:

@objc func progressDidChange(notification: NSNotification) {
    guard let routeProgress = notification.userInfo?[RouteControllerNotificationUserInfoKey.routeProgressKey] as? RouteProgress,
        let location = notification.userInfo?[RouteControllerNotificationUserInfoKey.locationKey] as? CLLocation else {
        return
    }

    // you have all information you probably need in routeProgress, f.E.
    let secondsRemaining = routeProgress.currentLegProgress.currentStepProgress.durationRemaining

    ...
}
Run Code Online (Sandbox Code Playgroud)