iOS refresh annotations on mapview

后端 未结 7 1672
悲&欢浪女
悲&欢浪女 2021-01-02 10:01

I have a mapview where the annotation\'s coordinates are constantly being updated but when I use setCoordinate, the annotation does not move. How do I refresh the annotation

7条回答
  •  孤城傲影
    2021-01-02 10:47

    Updated (to reflect the solution):

    Having your own custom annotations and implementing setCoordinate and/or synthesizing coordinate may cause issues.

    Source: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html

    Previous solution:

    You can simply remove all of the annotations and then re-add them.

    [mapView removeAnnotations:[mapView.annotations]];
    
    [mapView addAnnotations:(NSArray *)];
    

    or remove them and re-add them one by one:

    for (id annotation in mapView.annotations)
    {
        [mapView removeAnnotation:annotation];
        // change coordinates etc
        [mapView addAnnotation:annotation]; 
    }
    

提交回复
热议问题