Mapbox NavigationController未显示路线

时间:2018-11-23 11:19:11

标签: ios swift mapbox

我正在使用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

路线未显示:但是路线方向和箭头显示在地图上

enter image description here

enter image description here

  

我的问题是:我如何识别该路线是否显示?

1 个答案:

答案 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)
}