首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >路径计算中的Sygic问题

路径计算中的Sygic问题
EN

Stack Overflow用户
提问于 2018-11-11 08:29:44
回答 1查看 196关注 0票数 1

当我试图在我的Sygic脱机地图视图中添加一个路由时,我遇到了一个问题。在调试器中,我得到了一条消息“路由接口:请求未知传输模式”。这是我写的代码:

代码语言:javascript
复制
   class SygicMapViewController: UIViewController, SYNavigationDelegate,SYRoutingDelegate,SYMapViewDelegate,CLLocationManagerDelegate{
    let mapView = SYMapView()
    let routing = SYRouting()
    var  locationManager = CLLocationManager()
    override func viewDidLoad() {
        super.viewDidLoad()
        mapView.delegate = self
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
        locationManager.requestAlwaysAuthorization()
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
    }
    func setupMapView(){
        let tiltFor2D: SYAngle = 0
        mapView.tilt = tiltFor2D
        mapView.zoom = 12
        mapView.rotation = 180
        mapView.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height:self.view.frame.size.height+20)
        self.view.addSubview(mapView)
        mapView.renderEnabled = true
    }
    func addMarkers(){

    }
    func mapView(_ mapView: SYMapView, didFinishInitialization success: Bool) {
        setupMapView()
        SYNavigation.shared().delegate = self
        routing.delegate = self
        let startPoint = SYGeoCoordinate(latitude: 37.270665, longitude:  9.873921)
        let endPoint = SYGeoCoordinate(latitude: 37.242681, longitude: 9.911932)
        computeRoute(from: startPoint!, to: endPoint!)
    }
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print(error)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func computeRoute(from fromCoordinate: SYGeoCoordinate, to toCoordinate:
        SYGeoCoordinate) {
        let startWaypoint = SYWaypoint(position: fromCoordinate, type: .start, name: "Begin")
        let endWaypoint = SYWaypoint(position: toCoordinate, type: .end, name: "End")
        let routingOptions = SYRoutingOptions()
        routingOptions.transportMode = .unknown// For other options see SYTransportMode
        routingOptions.routingType = .economic// For other options see SYRoutingType
        routing.computeRoute(startWaypoint, to: endWaypoint, via: nil, with: routingOptions)
    }

    func routing(_ routing: SYRouting, computingFailedWithError error: SYRoutingError) {
        print(error)
    }

    func routing(_ routing: SYRouting, didComputePrimaryRoute route: SYRoute?) {
        SYNavigation.shared().start(with: route)
        // You might want to put it also on the map
        let mapRoute = SYMapRoute(route: route!, type: .primary)
        mapView.add(mapRoute)
        mapView.cameraMovementMode = .followGpsPosition
    }
}

我通过在computeRoute方法中选择本地路由变量来纠正这个问题,并在地图视图实现后进行了一些更改以触发computeRoute方法

EN

回答 1

Stack Overflow用户

发布于 2018-11-11 21:58:27

实际上,我在代码中看到了两个问题。

  1. func computeRoute(from fromCoordinate: SYGeoCoordinate, to toCoordinate: SYGeoCoordinate)中,定义局部变量routing,它隐藏实例变量。这会导致路由在计算任何路由之前被取消分配。因此,只需从该方法中删除该let routing = SYRouting(),并使用实例routing变量即可。
  2. 另一个也可能是一个问题,并造成问题。在地图初始化之前,您可以在viewDidLoad中开始路由。然后,如果路由更快,您将添加SYRoute对象进行映射,这可能会崩溃。我知道这只是一些快速的设置,但为了避免任何问题,请将调用转移到computeRoute,至少转移到mapView(_, didFinishInitialization)方法。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53247032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档