How to move a MKAnnotation without adding/removing it from the map?

前端 未结 11 1098
情深已故
情深已故 2020-12-13 06:22

Is it possible to move the coordinate of a MKAnnotation without adding and removing the annotation from the map?

11条回答
  •  北海茫月
    2020-12-13 06:47

    After you update the coordinates or some other properties of the annotation, just call following MKMapViewDelegate method to redraw your annotation:

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation;
    

    e.g.:

    myAnnotation.coordinate = CLLocationCoordinate2DMake([newLat doubleValue], [newLon doubleValue]);
    [self mapView:self.mapView viewForAnnotation:myAnnotation];
    

提交回复
热议问题