删除具有特定 pinColor 的 MKMapView 注释?
是否可以删除给定 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我现在无法测试这一点,但是您尝试过吗:
至于用户添加的内容,您可能需要自己跟踪这些内容。您还可以创建自己的 MKPinAnnotation 子类。在该子类上,添加属性
。如果addedByUser是由用户添加的,您可以将它们设置为true,然后使用上面类似的方法过滤掉那些(例如@“addedByUser == YES”)。
I am not able to test this right now, but have you tried:
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
. 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").
也许将每组注释保存在指向这些注释的指针数组(NSMutableArray)中,然后仅删除它们?
Maybe keeping each group of annotations in an array (NSMutableArray) of pointers to those annotations and then removing only them?