简体   繁体   English

MapKit - 如何将用户位置图标更改为默认值

[英]MapKit - How to change user location icon to default

I'm trying to change my pins color, but when I'm adding the code to switch annotation it also changes my location icon (from blue dot to a pin).我正在尝试更改我的图钉颜色,但是当我添加代码以切换注释时,它也会更改我的位置图标(从蓝点到图钉)。 Any tips how to restore default user location icon?任何提示如何恢复默认用户位置图标?

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "MyMarker")
    switch annotation.title!! {
        case "Ślęża":
            annotationView.markerTintColor = UIColor(red: (69.0/255), green: (95.0/255), blue: (170.0/255), alpha: 1.0)
        case "Śnieżnik":
            annotationView.markerTintColor = UIColor(red: (52.0/255), green: (114.0/255), blue: (1.0/255), alpha: 1.0)
        case "test":
            annotationView.markerTintColor = UIColor(red: (246.0/255), green: (233.0/255), blue: (212.0/255), alpha: 1.0)
        case "Brooklyn Bridge":
            annotationView.markerTintColor = UIColor(red: (146.0/255), green: (187.0/255), blue: (217.0/255), alpha: 1.0)
        default:
            annotationView.markerTintColor = UIColor.blue
    }
    return annotationView
}

Add a check to exclude it添加检查以排除它

guard !(annotation is MKUserLocation) else { return nil }
let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "MyMarker")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM