【发布时间】:2020-01-24 11:30:41
【问题描述】:
我拖了 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
}
我该如何解决这个问题,如果注释和用户的位置相同,它也会显示注释,而不仅仅是用户的当前位置?
【问题讨论】:
-
如果我正在阅读此内容,您想要添加的注释是否与用户当前位置的坐标相同?
-
是的,注释图钉“可能”与用户的当前位置相同,如果是这样……它应该显示在用户当前位置的上方。
-
看看这个question
标签: ios swift mapkit mkmapview mapkitannotation