Remove MKMapView Annotations with a certain pinColor?

后端 未结 2 1503
死守一世寂寞
死守一世寂寞 2020-12-16 06:56

Is it possible to remove all annotations on a given MKMapView of a given pinColor? I\'m trying to clear all user-entered annotations (pins) on my map before displaying new o

相关标签:
2条回答
  • 2020-12-16 07:05

    I am not able to test this right now, but have you tried:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"pinColor == %d",  MKPinAnnotationColorGreen];
    [myMapView removeAnnotations:[myMapView.annotations filteredArrayUsingPredicate:predicate]];
    

    As for the ones added by the user, you might need to keep track of those yourself. You could also create your own subclass of MKPinAnnotation. On that subclass, add the property

    @property (nonatomic, BOOL) addedByUser;
    

    . You could set addedByUser to true if they were added by the user and then filter out those using a similar approach above (eg. @"addedByUser == YES").

    0 讨论(0)
  • 2020-12-16 07:24

    Maybe keeping each group of annotations in an array (NSMutableArray) of pointers to those annotations and then removing only them?

    0 讨论(0)
提交回复
热议问题