如何解决如何将默认的蓝色注释用于用户位置而不是自定义注释?
我的地图上有自定义注释,现在我希望能够显示用户位置以及自定义注释。但是,当我显示用户位置时,它使用的是自定义注释,而不是默认的蓝色注释。有没有一种方法可以使用户位置使用默认值?
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
}
谢谢
解决方法
按以下步骤操作:
func locationManager(manager: CLLocationManager,didUpdateLocations locations: [CLLocation]) {
yourCustomAnnotation = CustomPointAnnotation()
yourCustomAnnotation.pinCustomImageName = "Marker"
yourCustomAnnotation.coordinate = location
yourCustomAnnotationView = MKPinAnnotationView(annotation: yourCustomAnnotation,reuseIdentifier: "pin")
map.addAnnotation(yourCustomAnnotationView.annotation!)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。