如何删除 MKMapView 上的所有注释
有没有一种简单的方法可以删除地图上的所有注释,而无需迭代 Objective-c 中所有显示的注释?
Is there a simple way to delete all the annotations on a map without iterating through all the displayed annotations in Objective-c?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
是的,方法如下
Yes, here is how
这是最简单的方法:
Here is the simplest way to do that:
以下是如何删除除用户位置之外的所有注释,明确写出,因为我想我会再次寻找这个答案:
Here's how to remove all annotations except the user location, written out explicitly because I imagine I will come looking for this answer again:
这与 Sandip 的答案非常相似,只是它不会重新添加用户位置,因此蓝点不会再次闪烁。
This is very similar to Sandip's answer, except that it doesn't re-add the user location so the blue dot doesn't blink on and off again.
您不需要保存任何对用户位置的引用。所需要做的就是:
只要将
mapView.showsUserLocation
设置为YES
,您仍然可以在地图上看到用户位置。将此属性设置为“YES”基本上会要求地图视图开始更新和获取用户位置,以将其显示在地图上。来自MKMapView.h
注释:You do not need to save any reference to user location. All that is needed is:
And as long as you have
mapView.showsUserLocation
set toYES
, you will still have user location on the map. Settings this property toYES
basically asks the map view to start updating and fetching user location, to to show it on the map. From theMKMapView.h
comments:斯威夫特2.0
简单且最好:
Swift 2.0
Simple and the best:
斯威夫特版本:
Swift version:
雨燕3
Swift 3
要删除一种类型的子类,您可以
在
PlacesAnnotation
是MKAnnotation
的子类的情况下执行此操作To remove one type of subclass you can do
where
PlacesAnnotation
is a subclass ofMKAnnotation
以下是从 MKMapView 中删除所有标记以及所有路线(如果有)的函数:
干杯
Here is the function to remove all markers as well as all routes (if any) from MKMapView:
Cheers