【发布时间】:2020-10-25 09:04:56
【问题描述】:
我的地图上有自定义注释,现在我希望能够显示用户位置以及自定义注释。但是,当我显示用户位置时,它使用自定义注释而不是默认的蓝色注释。有没有办法让用户位置使用默认值?
我使用以下内容显示用户位置:
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
map.showsUserLocation = true
自定义注解使用以下设置:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let reuseIdentifier = "pin"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier)
if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
annotationView?.canShowCallout = false
} else {
annotationView?.annotation = annotation
}
annotationView?.image = UIImage(named: "Marker")
return annotationView
}
谢谢
【问题讨论】:
-
如果您不想使用自定义注释,为什么不删除?
-
我想对除显示用户位置的注释之外的所有注释使用我的自定义注释 - 当我调用 showUserLocation 它自然会使用此自定义注释
-
那么您可以使用不同的自定义注释吗?
-
我发现我需要检查进入 viewFor 的注释以检查它是否属于 MKUserLocation 类型 - 如果是,那么我只需返回 nil。
-
它是通过以下方式实现的:stackoverflow.com/questions/61785563/…
标签: swift mapkit mkannotation