如何在逐步导航中找出重新路由的数量?

how to find out the number of reroutes in a step-by-step navigation?

我是 Mapbox 开发新手。我想知道是否有办法找出一次导航中发生了多少次重新路由? iOS/Swift 中的任何示例会更好。非常感谢。

你可以收听 RouteControllerDidReroute notification

如需额外数据和更多信息,您可以注册到 RouteController

的相关 delegate: RouterDelegate 方法

主要是func router(_ router: Router, willRerouteFrom location: CLLocation)

根据文档:

Called immediately before the router calculates a new route.

This method is called after router(:shouldRerouteFrom:) is called, and before router(:didRerouteAlong:) is called.

最后,如果使用 Mapbox 提供的默认 NavigationViewController。 您可以注册为委托人 (NavigationViewControllerDelegate) 以获取以下更新:

func navigationViewController(_ navigationViewController: NavigationViewController, willRerouteFrom location: CLLocation?)

func navigationViewController(_ navigationViewController: NavigationViewController, didRerouteAlong route: Route)