我有一个 MKMapKit,我正在使用从 API 获取的数据填充注释。每个注释都有一个标题、描述、URL 和坐标。我有一个添加到导航栏的按钮来获取更多结果并填充更多注释。问题在于,当 API 用完新结果时,会使用已获取的注释的副本填充地图。我正在尝试使用 if 语句从数组中删除重复的注释,但它不起作用。有什么建议么?提前致谢。
-(void)layAnnotations
{
if (self.annotations) {
[self.mapView removeAnnotations:self.annotations];
}
self.annotations = [NSMutableArray array];
for (Object *aObject in self.objectArray) {
CLLocationCoordinate2D coordinate;
coordinate.latitude = [aObject.latitude floatValue];
coordinate.longitude = [aObject.longitude floatValue];
Annotations *annotation = [[Annotations alloc] init];
annotation.title = aObject.objectTitle;
annotation.subtitle = aObject.description;
annotation.url = aObject.url;
annotation.coordinate = coordinate;
//attempting to filter duplicates here
if (![self.annotations containsObject:annotation]) {
[self.annotations addObject:annotation];
}
annotation = nil;
}
[self mutateCoordinatesOfClashingAnnotations:self.annotations];
[self.mapView addAnnotations:self.annotations];
}