A custom AnnotationView is updated with new coordinates. But the problem is that it visually updates only after some manipulations with MKMapView, e.g. zooming or moving. What should I do to manually update visual position on a map?
PS. I've tried to change region to current map's region. But it does change zoom. It's strange.
[mapView setRegion:[mapView region] animated:YES];
if your adding your annoations from a thread it wont work. i had the same problem and just wrapping my function that was adding the annotations with the following worked
There's no reason you can't remove and then re-add the annotation. That's probably way more performant than moving the entire map, even if its a fake move.
Here is the interface to MapAnnotation:
And here is the implementation:
I solved this error with an asynchronous call, at least 0.5 delay.
e.g.:
[self performSelector:@selector(redrawPins) withObject:nil afterDelay:0.5];
Where "redrawPins" is the function which adds and removes pins.
I am a little shoked after hours of research. The answer is just:
Do not ask me why, but it updates a mapview and it's what i was need.
MKMapView
observes the coordinate property of annotations viaKVO
. You simply need to observe properKVO
protocol and send the annotationwillChangeValueForKey:
anddidChangeValueForKey:
with keypath of@"coordinate"
before and after you update the coordinates.Likewise
title
andsubtitle
are also observed byMKMapView
. so if you update those and want the value in the callout to change automatically without any effort on your part, just do the same: callwillChangeValueForKey:
anddidChangeValueForKey: