我已经拖曳了UIViewControllers,第一个显示了一个带有注释和用户当前位置的MKMapKitView,在第二个viewController中,我将构造将显示在第一个viewController上的注释。
我发现,如果用户的位置和注释相同,则mapView将仅显示用户的当前位置。
这是我创建注释的代码:
func addAnnotiation(for locationCoordinate: CLLocationCoordinate2D) {
let annotationPoint = MKPointAnnotation()
annotationPoint.coordinate = locationCoordinate
mapView.addAnnotation(annotationPoint)
}
我的mkmapviewdelegate
方法:
func mapView(_ mapView: MKMapView,viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "Annotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation,reuseIdentifier: identifier)
annotationView!.canShowCallout = true
} else {
annotationView!.annotation = annotation
}
return annotationView
}
我怎么解决这个问题,如果注释和用户的位置相同,它将不仅显示用户当前的位置,而且还会显示注释?