删除具有特定 pinColor 的 MKMapView 注释?

发布于 2024-10-18 07:09:52 字数 359 浏览 1 评论 0原文

是否可以删除给定 pinColor 的给定 MKMapView 上的所有注释?我试图在为我的应用程序的一部分显示新注释之前清除地图上所有用户输入的注释(图钉),但我不知道我可以有多么精细地有选择地删除注释...

我想仅删除具有 MKPinAnnotationColorGreen(绿色)引脚的所有注释,但如果有一种方法可以跟踪这些引脚,我也可以简单地删除用户输入的所有引脚。

我知道我可以简单地执行以下操作:

[myMapView removeAnnotations:myMapView.annotations];

...然后重新绘制我想要的所有注释,但这似乎浪费资源。

有什么建议吗?

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 ones for a part of my app, but I didn't know how granular I can be in selectively removing annotations...

I'd like to just remove all annotations that have MKPinAnnotationColorGreen (green) pins, but I'd also be able to simply remove all pins entered by the user, if there's a way I could track those.

I know I could simply do:

[myMapView removeAnnotations:myMapView.annotations];

... then redraw all the annotations I want, but that seems like a waste of resources.

Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌上青苔 2024-10-25 07:09:52

我现在无法测试这一点,但是您尝试过吗:

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

至于用户添加的内容,您可能需要自己跟踪这些内容。您还可以创建自己的 MKPinAnnotation 子类。在该子类上,添加属性

@property (nonatomic, BOOL) addedByUser;

。如果addedByUser是由用户添加的,您可以将它们设置为true,然后使用上面类似的方法过滤掉那些(例如@“addedByUser == YES”)。

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").

标点 2024-10-25 07:09:52

也许将每组注释保存在指向这些注释的指针数组(NSMutableArray)中,然后仅删除它们?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文