首页 > 解决方案 > Swift mapkit如何隐藏用户的定位销

问题描述

我找不到任何关于此的文档,所以也许我无论如何都不可能问。我需要显示用户位置的蓝点。我的地图视图充满了图钉,有时我的用户正在单击用户位置的蓝色圆圈,这会打开一个小的用户图片图钉。我怎样才能删除它?如果后面有东西,那就很烦人了。

用户定位销

到目前为止,我必须确定何时打开注释视图:

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    if(view.annotation?.isKind(of: MKUserLocation.self) != true){
        print("test");
    }
}

有没有办法取消它的显示?

标签: iosswiftmapkitmapkitannotation

解决方案


您拥有 99% 的解决方案 - 您已确定何时选择了用户位置注释。完成任务所需要做的就是取消选择它;

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        
    if view.annotation is MKUserLocation {
        mapView.deselectAnnotation(view.annotation, animated: false)
        return
    }

    // Handle selection of other annotations if required...
}

推荐阅读