gpt4 book ai didi

swift - 计算路线的 Sygic 问题

转载 作者:行者123 更新时间:2023-11-28 05:50:11 24 4
gpt4 key购买 nike

当我尝试在我的 Sygic 离线 map View 中添加路线时遇到问题。在调试器中,我收到这条消息“路由接口(interface):询问未知的传输模式。”这是我写的代码:

   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 方法中选择本地路由变量来纠正这个问题,我做了一些更改以在 mapview 初始化之后触发 computeRoute 方法

最佳答案

实际上我发现您的代码有两个问题。

  1. func computeRoute(from fromCoordinate: SYGeoCoordinate, to
    toCoordinate: SYGeoCoordinate)
    你定义局部变量routing它隐藏了实例变量。这导致路由是在它可以计算任何路由之前释放。所以只需删除它let routing = SYRouting() 来自该方法并使用实例路由变量。
  2. 另一个也可能是一个问题并导致问题。你先来在初始化 map 之前在 viewDidLoad 中进行路由。那么如果路由更快你将添加 SYRoute 对象来映射和那可能会崩溃。我知道这只是一些快速设置,但是为避免任何问题,至少将调用 computeRoute 移动到mapView(_, didFinishInitialization) 方法。

关于swift - 计算路线的 Sygic 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53247032/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com