0

每当在我的 MapView 上单击 MKPlacemark 时,我都会尝试执行某个功能。此功能从地标中提取信息并将其显示在单独的视图中。我试过用

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {}

但这似乎不起作用。我不确定是否必须命名每个地标,我避免这样做,因为我已经在名称中显示位置数据(如我的代码中所示)。任何帮助将非常感激。我的代码:

启动地标(这种情况发生了很多次,变量已经被实例化了):

let coords = CLLocationCoordinate2DMake(latOfPlace!, lonOfPlace!)
let address = [CNPostalAddressStreetKey: addressStreetKey, CNPostalAddressCityKey: addressCityKey, CNPostalAddressPostalCodeKey: addressPostalCodeKey, CNPostalAddressISOCountryCodeKey: addressISOCountryCodeKey]
let place = MKPlacemark(coordinate: coords, addressDictionary: address)
self.mapView.addAnnotation(place)
4

1 回答 1

1

您需要在里面设置委托viewDidLoad

self.mapView.delegate = self

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
  guard let ann = view.annotation as? MKPlacemark else { return }
  print(ann)
}
于 2019-03-16T20:06:49.593 回答