我的Map上有自定义注解,现在我希望能够显示用户位置以及自定义注解。但是,当我显示用户位置时,它使用自定义注解而不是默认的蓝色注解。是否有方法使用户位置使用默认值?
我得到用户的位置显示使用下面的:
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
}
型
谢谢
3条答案
按热度按时间h7wcgrx31#
像下面这样做:
字符串
qybjjes12#
我在处理同样的问题。在“viewFor annotation”委托方法的顶部使用这个检查:
字符串
这将防止自定义您的用户位置
evrscar23#
你可以在MKMapViewDelegate中这样做:
字符串