我正在使用mapbox进行导航,我的问题是当我显示NavigationController
时,有时该路线未显示在地图上,而当我关闭应用程序并重新打开它时,它运行正常。
这是我的代码,用于显示NavigationController
:
let options = NavigationRouteOptions(waypoints: [origin, destination], profileIdentifier: MBDirectionsProfileIdentifier.automobile)
Directions.shared.calculate(options) { (waypoints, routes, error) in
if error != nil {
}
guard let route = routes?.first else {
print("Empty")
return
}
self.navViewController = NavigationViewController(for: route, directions: Directions.shared, styles: [CustomNightStyle()], locationManager: NavigationLocationManager()) //NavigationLocationManager() SimulatedLocationManager(route: route)
self.navViewController?.mapView?.delegate = self
self.navViewController?.delegate = self
self.wayPointLocation.append(origin)
self.addChildViewController(self.navViewController!)
self.navigationView.addSubview((self.navViewController?.view)!)
self.navViewController?.view.translatesAutoresizingMaskIntoConstraints = false
路线未显示:但是路线方向和箭头显示在地图上
我的问题是:我如何识别该路线是否显示?
答案 0 :(得分:0)
我找到了:)。
加载导航地图后,我从MGLMapViewDelegate
委托方法mapViewDidFinishLoadingMap
获取事件。
在mapViewDidFinishLoadingMap
内,我检查了地图视图样式图层属性。
if let _ = vcNav.mapView?.style?.layer(withIdentifier: "routeLayer") {
print("Found ::")
} else {
print("Not Found ::")
vcNav.mapView?.removeRoutes()
vcNav.mapView?.removeWaypoints()
vcNav.mapView?.showRoutes([vcNav.route])
vcNav.mapView?.showWaypoints(vcNav.route)
}