[英]Drawn annotation moves to user's location after route is calculated - Skobbler
After I initialise map I add one annotation to a certain coordinate 初始化地图后,我将一个注释添加到某个坐标
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)
}
After I do this, annotation is placed at the right coordinates. 完成此操作后,注释将放置在正确的坐标处。 But right after I calculate route, that same annotation is redrawn to the route start coordinates. 但是,在我计算路线之后,该标注将重新绘制到路线起始坐标。
This is the code I use for calculating a route (And i call it right after I initialise map and add annotation) 这是我用于计算路线的代码(在初始化地图并添加注释后立即调用它)
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)
}
So why does that annotation gets redrawn to another coordinate (always start of the route) after the route is calculated? 那么,为什么在计算路线后该注释会重绘到另一个坐标(始终是路线的起点)?
Set the annotation's ID to something > 10. 将注释的ID设置为> 10。
For some reason, the SDK uses the internal 0 and 1 ids for the start and end destination flag and I guess that by not assigning a specific ID to your annotation it automatically receives one of those protected IDs. 由于某种原因,SDK将内部0和1 ID用作开始和结束目标标志,我想如果不为您的注释分配特定的ID,它会自动接收这些受保护的ID之一。
Note: I know that this has been addressed in the Android version - we will check in the iOS versions 注意:我知道这已在Android版本中解决-我们将检入iOS版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.