除了用户位置注释之外,如何从MKMapView中删除所有注释? [英] How do I remove all annotations from MKMapView except the user location annotation?

查看:172
本文介绍了除了用户位置注释之外,如何从MKMapView中删除所有注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 removeAnnotations mapView 中删除​​我的注释,但同样删除用户位置ann。如何防止这种情况,或者如何让用户回来查看?

I use removeAnnotations to remove my annotations from mapView but same it remove user location ann. How can I prevent this, or how to get user ann back to view?

NSArray *annotationsOnMap = mapView.annotations;
        [mapView removeAnnotations:annotationsOnMap];


推荐答案

更新:

当我尝试使用iOS 9 SDK时,不再删除用户注释。你可以简单地使用

When I tried with the iOS 9 SDK the user annotation is no longer removed. You can simply use

mapView.removeAnnotations(mapView.annotations)






历史答案(适用于在iOS 9之前在iOS上运行的应用):


Historical answer (for apps that run on iOS before iOS 9):

试试这个:

NSMutableArray * annotationsToRemove = [ mapView.annotations mutableCopy ] ;
[ annotationsToRemove removeObject:mapView.userLocation ] ;
[ mapView removeAnnotations:annotationsToRemove ] ;

编辑:Swift版本

let annotationsToRemove = mapView.annotations.filter { $0 !== mapView.userLocation }
mapView.removeAnnotations( annotationsToRemove )

这篇关于除了用户位置注释之外,如何从MKMapView中删除所有注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆