Results 1 to 8 of 8

Thread: [iOS] Annotation moves when zooming in

  1. #1
    Erfahrener skobbler
    Join Date
    11.02.2015
    Posts
    123

    [iOS] Annotation moves when zooming in

    I have the weirdest problem. An annotation on my map is jumping to another position when I pinch-zoom the map. I'm using SKMaps 2.4.

    The situation is as follows:
    I have a route with via 10 points. I have a customized annotation for the route start, the route end and also for the via points on the route. When I add the annotations to the mapView they are in the correct position, like in screenshot below.
    2015-04-23 21.58.09.jpg

    Then I start zooming in and viaPoint1 annotation spontaneously jumps to the same coordinate as the route end-point. See screenshot.
    2015-04-23 21.58.17.jpg

    I have the same problem with other routes! It's always the first viaPoint annotation that always jumps to the route end-point. All the other annotations remain in their correct position.

    I use below function to add the annotation to the mapView.

    Code:
    func addAnnotationToMapView(mapView: SKMapView, #id: Int32, #coordinate: CLLocationCoordinate2D, #image: UIImage, #width: CGFloat, #height: CGFloat, #offsetX: CGFloat, #offsetY: CGFloat, #reuseIdentifier: String) {
        let imageView = UIImageView(frame: CGRectMake(0.0, 0.0, width, height))
        imageView.contentMode = UIViewContentMode.ScaleAspectFit
        imageView.image = image
        let annotationView = SKAnnotationView(view: imageView, reuseIdentifier: reuseIdentifier)
        let annotation = SKAnnotation()
        annotation.annotationView = annotationView
        annotation.identifier = id
        annotation.location = coordinate
        annotation.offset = CGPointMake(offsetX, offsetY)
        mapView.addAnnotation(annotation, withAnimationSettings: nil)
    }
    And I call this function for the start and end annotation from viewDidAppear:
    Code:
    addAnnotationToMapView(self.mapView, id: 98, coordinate: track.start.coordinate, image: UIImage(named: trackStartMarker)!, width: 40, height: 40, offsetX: 0, offsetY: 30, reuseIdentifier: trackStartMarker)
            addAnnotationToMapView(self.mapView, id: 99, coordinate: track.end.coordinate, image: UIImage(named: trackEndMarker)!, width: 40, height: 40, offsetX: 0, offsetY: 38, reuseIdentifier: trackEndMarker)
    trackStartMarker and trackEndMarker are predefined strings.

    And for the viaPoints later-on, by user tapping a button:
    Code:
    for var i = 0; i < viaPointArray.count; ++i {
                let vp = viaPointArray[i]
                addAnnotationToMapView(mapView, id: Int32(i+1), coordinate: vp.coordinate, image: viaPointIconWithNr(i+1), width: 20, height: 37, offsetX: 0, offsetY: 32, reuseIdentifier: "vp\(i+1)")
            }
    viaPointIconWithNr(number: Int) is a function that return the viaPoint image with the number indicated.

    As you can see I'm using unique identifiers (viaPointArray never has more then 50 points) and all the reuseIdentifiers are also unique.

    Not sure what's going on here. It's definitely very weird :-)

    I thought I had a workaround for it: In the callback functions didDoubleTapAtCoordinate and didStartRegionChangeFromRegion I added this:
    Code:
            mapView.removeAnnotationWithID(1)
            addAnnotationToMapView(mapView, id: Int32(1), coordinate: viaPointArray[0].coordinate, image: viaPointIconWithNr(1), width: 20, height: 37, offsetX: 0, offsetY: 32, reuseIdentifier: "vp1")
    However this doesn't really work as the annotation moves AFTER the pinch-zoom action i.e. AFTER the callbacks were called. So then it requires another pinch-zoom action to initiate the callback and put the annotation back in it's place. That does work. I'm thinking it has something to do with redrawing the mapView and it's annotations after a zoom action. This, if at all, is happening inside the framework so perhaps you can shed some more light on it?

    A bit off topic, I also have 2 older threads where I recently replied to (was tackling some other problems so it took me some time to reply).
    I didn't get a response yet, while usually response is next day. Not trying to rush you or anything, just in case you're not monitoring these older threads anymore.
    http://forum.skobbler.com/showthread...roblems-in-iOS (this one might actually be related to the issue described here)
    http://forum.skobbler.com/showthread...as-been-loaded

    Thanks very much in advance for any help or pointers you could give me.
    Cheers,
    Guido

  2. #2
    Erfahrener skobbler
    Join Date
    11.02.2015
    Posts
    123
    Did some more digging and found a workable workaround.
    In stead of adding
    Code:
    mapView.removeAnnotationWithID(1)
    addAnnotationToMapView(mapView, id: Int32(1), coordinate: viaPointArray[0].coordinate, image: viaPointIconWithNr(1), width: 20, height: 37, offsetX: 0, offsetY: 32, reuseIdentifier: "vp1")
    to didDoubleTapAtCoordinate and didStartRegionChangeFromRegion I added it to didChangeToRegion

    This method is called many times DURING a zoom action so it's a bit heavy, but it's the only thing that works.
    I also tried adding it to didEndRegionChangeToRegion, but that didn't work.

    In stead of above code I also tried this, more light, code:
    Code:
    mapView.annotationForIdentifier(1).location = viaPointArray[0].coordinate
    but strangely enough that didn't work either.

    During my investigation I could conclude that, although the annotation moves, the actual location property of the annotation is not changing. I tested this by adding following code to didChangeToRegion:
    Code:
    if tempCoor.longitude != mapView.annotationForIdentifier(1).location.longitude {
                    println("annotation location shifted")
                }
    tempCoor is set to the annotationLocation just after adding it to the map.

    Well, although I have a workaround now, a "real" solution would be better as this is a quite "heavy" workaround.

    Cheers and regards,
    Guido

  3. #3
    Oberskobbler
    Join Date
    22.07.2014
    Posts
    399
    Happy to hear you managed to find a way to solve it- we'll keep a close eye on it for the next release

  4. #4
    Erfahrener skobbler
    Join Date
    11.02.2015
    Posts
    123
    Still the same problem in 2.5.1
    Any luck finding a solution?

  5. #5
    Oberskobbler
    Join Date
    22.07.2014
    Posts
    399
    We haven't experienced the issue in 2.5.1. Please allow us to check that again

  6. #6
    Erfahrener skobbler
    Join Date
    11.02.2015
    Posts
    123
    By dumb luck I found out that this mysterious behaviour occurs for the annotation with identifier 0 (zero). If I change the identifier the mysterious behaviour is gone in my case.
    My guess is, but perhaps you (Adela) can confirm, is that somehow the 0 identifier is reserved for the current location indicator.

  7. #7
    Oberskobbler
    Join Date
    22.07.2014
    Posts
    399
    Hi guidove,

    I'll have to check this information with our developers. I'll get back with an update

  8. #8
    Erfahrener skobbler
    Join Date
    11.02.2015
    Posts
    123
    Be sure to also include this thread in your communication. It's the same problem. http://forum.skobbler.com/showthread...2nd-Annotation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •