从mapview中删除特定注释

时间:2013-04-30 13:34:38

标签: iphone mapkit

在我的mapview中,我创建了cafebarnight_clubrestaurant等针脚。我如何编码只删除特定点cafe。我已使用下面的代码成功删除所有注释。我无法弄清楚如何删除一个特定的(而不是全部)。

for (id<MKAnnotation> annotation in routeMapView.annotations) 
{
  if ([annotation isKindOfClass:[MapPoint class]]) 
  {
    [routeMapView removeAnnotation:index=annotation];
  }
}

2 个答案:

答案 0 :(得分:3)

可能会帮助您尝试使用此功能。

for (id annotation in mapView.annotations)
{
    if ([[annotation title] isEqualToString:@"cafe"])
          [self.mapView removeAnnotation:annotation];
}

答案 1 :(得分:1)

您可以使用NSPredicate来处理

这样的情况
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"pinName == %@",  @"Cafe"];
[myMapView removeAnnotations:[myMapView.annotations filteredArrayUsingPredicate:predicate]];

上面将删除所有名为cafe的注释。

有关详细信息,您可以看到此答案 Remove MKMapView Annotations with a certain pinColor?