【问题标题】:Drawn annotation moves to user's location after route is calculated - Skobbler计算路线后,绘制的注释移动到用户的位置 - Skobbler
【发布时间】:2016-02-26 20:53:01
【问题描述】:

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

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

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

【问题讨论】:

    标签: ios swift skmaps


    【解决方案1】:

    将注释的 ID 设置为 > 10。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-28
      • 2013-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多