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

时间:2016-02-25 14:44:36

标签: ios swift skmaps

初始化地图后,我将一个注释添加到某个坐标

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

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

1 个答案:

答案 0 :(得分:2)

将注释的ID设置为> 10。

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

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