[英]Remove a specific annotation from mapview
In my mapview I am creating pins like cafe
, bar
, night_club
, and restaurant
. 在地图视图中,我正在创建图钉,例如cafe
, bar
, night_club
和restaurant
。 How can I code to remove only the a specific point, cafe
for example. 我该如何编码才能仅删除特定的地点,例如cafe
。 I have used the code below to successfully remove ALL the annotations. 我已使用下面的代码成功删除了所有注释。 I can't figure out how to delete one specific one (instead of all of them). 我不知道如何删除一个特定的(而不是全部删除)。
for (id<MKAnnotation> annotation in routeMapView.annotations)
{
if ([annotation isKindOfClass:[MapPoint class]])
{
[routeMapView removeAnnotation:index=annotation];
}
}
It may help you please try to use this one. 它可能会帮助您,请尝试使用此功能。
for (id annotation in mapView.annotations)
{
if ([[annotation title] isEqualToString:@"cafe"])
[self.mapView removeAnnotation:annotation];
}
You can use NSPredicate for the situation like 您可以将NSPredicate用于以下情况
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"pinName == %@", @"Cafe"];
[myMapView removeAnnotations:[myMapView.annotations filteredArrayUsingPredicate:predicate]];
Above will remove all the annotations named cafe. 上面将删除所有名为cafe的注释。
For more info you can see this answer Remove MKMapView Annotations with a certain pinColor? 有关更多信息,您可以看到此答案删除具有特定pinColor的MKMapView注释?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.