计算路线后绘制的注释移动到用户的位置 - Skobbler

Drawn annotation moves to user's location after route is calculated - Skobbler

初始化地图后,我在某个坐标上添加了一个注释

func initMap(){

    SKRoutingService.sharedInstance().navigationDelegate = self
    SKRoutingService.sharedInstance().routingDelegate = self
    SKRoutingService.sharedInstance().mapView = self.mapView
    SKRoutingService.sharedInstance().mapView?.delegate = self
    SKRoutingService.sharedInstance().mapView?.centerOnCurrentPosition()
    SKRoutingService.sharedInstance().mapView?.animateToZoomLevel(16)
    SKRoutingService.sharedInstance().mapView?.settings.showAccuracyCircle = false
    SKRoutingService.sharedInstance().mapView?.settings.showStreetNamePopUps = true
    SKRoutingService.sharedInstance().mapView?.mapScaleView.hidden = true

    setCheckpointAnnotation()


}


    func setCheckpointAnnotation(){

    let annotationViewHolder = UIView(frame: CGRectMake(0,0,40,80))
    let annotationImageView = UIImageView(frame: CGRectMake(0,0,40,80))

    annotationImageView.image = UIImage(named: "HorseHead.png")
    annotationViewHolder.addSubview(annotationImageView)

    let annotation = SKAnnotation()
    annotation.location = self.checkpointLocation
    let annotationView = SKAnnotationView(view: annotationViewHolder, reuseIdentifier: "Annotation")
    annotation.annotationView = annotationView

    SKRoutingService.sharedInstance().mapView?.addAnnotation(annotation, withAnimationSettings: .None)
}

在我这样做之后,注释被放置在正确的坐标上。 但是在我计算路线之后,相同的注释被重新绘制到路线起始坐标。

这是我用来计算路线的代码(我在初始化地图和添加注释后立即调用它)

 func calculateRoute(){
    let route = SKRouteSettings()
    //var viaPointsArray = [SKViaPoint]()



    self.checkpoints.removeFirst()

    route.startCoordinate = self.userLocation
    route.destinationCoordinate = self.checkpointLocation

    //route.viaPoints = viaPointsArray

    route.shouldBeRendered = true // If false, the route will not be rendered.
    route.routeMode = SKRouteMode.Pedestrian

    route.maximumReturnedRoutes = 1
    route.routeRestrictions.avoidHighways = true

    SKRoutingService.sharedInstance().calculateRoute(route)
}

那么为什么在计算路线后该注释会重新绘制到另一个坐标(始终是路线的起点)?

将注释的 ID 设置为 > 10。

出于某种原因,SDK 使用内部 0 和 1 id 作为开始和结束目标标志,我想如果不为您的注释分配特定 ID,它会自动接收其中一个受保护的 ID。

注意: 我知道这已在 Android 版本中解决 - 我们将检查 iOS 版本