How do I remove all annotations from MKMapView except the user location annotation?

后端 未结 8 1275
天命终不由人
天命终不由人 2020-12-24 06:19

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

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 07:18

    For Swift you can simply use a one-liner:

    mapView.removeAnnotations(mapView.annotations)
    

    Edit: As nielsbot mentioned it will also remove the user's location annotation unless you have set it up like this:

    mapView.showsUserLocation = true
    

提交回复
热议问题