iOS refresh annotations on mapview

后端 未结 7 1645
悲&欢浪女
悲&欢浪女 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

    Removing all existing annotations, and re-adding the new or updated annotation list will refresh the mapView. Firstly I tried:

    mapView.annotations.removeAll()
    

    but received the error:

    "Value of type '(MKMapRect) -> Set' has no member 'removeAll'"
    

    However this worked:

    for annotation in mapView.annotations{
        mapView.removeAnnotation(annotation)
    }
    // .. code to add the new or updated annotation list
    

提交回复
热议问题