steeffeen
steeffeen

Reputation: 47

Adding and removing annotations from MapView leads to a blink

in my app I'm adding and removing annotations to my map view, but actually even if I first add the new ones and then remove the old ones there is a blink of the annotations

The new annotations are received from the internet and so I can't just remove them from the array of the new ones...

My question is how does it come to the blink behavior and how I can avoid this?

I don't want to iterate through the annotations and compare each's location... So I tried to delay the remove and ended up at 0.2 seconds. With exactly this delay there is no visible blink, but this isn't desirable at all.

Thanks

    NSMutableArray *annotationsToRemove = [[NSMutableArray alloc] initWithArray:[_mapView annotations]]; 
    [annotationsToRemove removeObject:[_mapView userLocation]];
    [_mapView addAnnotations:locations];
    // [_mapView performSelector:@selector(removeAnnotations:) withObject:annotationsToRemove afterDelay:0.2];
    [_mapView removeAnnotations:annotationsToRemove];

("locations" is my array of new annotations)

Upvotes: 2

Views: 1348

Answers (1)

nevan king
nevan king

Reputation: 113777

The blink always happens when adding an annotation just after removing one. If you have control of the web service, add a unique id, check if an annotation with that id already exists on your map and only add a new annotation if it doesn't. If you can't add an id, check using the latitude and longitude (which should probably be unique). Iterating through them won't be expensive.

Upvotes: 2

Related Questions