Search code examples
iosswiftskmaps

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?


Solution

  • Set the annotation's ID to something > 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.

    Note: I know that this has been addressed in the Android version - we will check in the iOS versions