如何在不更改 Swift 中默认位置引脚的情况下更改 MapKit 中的markerTintColor?

Jam*_*Voo 0 annotations mapkit ios swift swift4

我有 MKMarkerAnnotationView 来更改地图上图钉的颜色。

func mapView(_ MapView:MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{

    let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")

    view.markerTintColor = .blue

    return view

}
Run Code Online (Sandbox Code Playgroud)

但是,当我启动我的应用程序时,我的默认位置标记会更改为。如何在不更改此标记的情况下更改引脚?查看位置的代码也很简单

 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    self.MapView.showsUserLocation = true
}
Run Code Online (Sandbox Code Playgroud)

感谢您的回答!:)

Lor*_*eto 5

您可以检查注释是否是用户位置,如下所示:

func mapView(_ MapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    if annotation is MKUserLocation {
        return nil
    }

    let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")
    view.markerTintColor = .blue
    return view
}
Run Code Online (Sandbox Code Playgroud)