【问题标题】:Annotation Title in MapKit is not visible anymoreMapKit 中的注释标题不再可见
【发布时间】:2021-08-17 08:29:39
【问题描述】:

我在星期一将一个应用程序上传到了 AppStore。一切正常。从星期四开始,添加注释的标题不再可见。

该应用有一系列兴趣点。每个都有一个标题和坐标。 PoI 正在显示,我可以过滤它们以获得标题。 但标题不可见。

【问题讨论】:

  • 请给我们一些相关的代码
  • func createAnnotations(locations: [[String : Any]]) { for location in locations { let annotations = MKPointAnnotation() annotations.title = location["title"] as? String annotations.coordinate = CLLocationCoordinate2D(latitude: location["latitude"] as! CLLocationDegrees, longitude: location["longitude"] as! CLLocationDegrees) myMapView.addAnnotation(annotations) } }

标签: annotations mapkit point-of-interest


【解决方案1】:

我只是通过添加以下函数来修复它。不幸的是,它只能通过点击图钉来显示标题。

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    guard annotation is MKPointAnnotation else { return nil }

    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
}

【讨论】:

  • MKMarkerAnnotationView代替pin,看看它能为你带来什么奇迹。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-17
相关资源
最近更新 更多