Swift 点击显示位置点的功能

Swift 点击显示位置点的功能,swift,mapkit,Swift,Mapkit,在地图中,我显示用户位置,如下所示: map.showsUserLocation = true 如果用户点击点,我想做点什么。有什么方法可以做到这一点吗?假设您使用的是MapKit,在MKMapViewDelegate方法中,您可以对用户点击MKAnnotationView作出反应 func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) { if let userLocation = view.annotat

在地图中,我显示用户位置,如下所示:

map.showsUserLocation = true

如果用户点击点,我想做点什么。有什么方法可以做到这一点吗?

假设您使用的是
MapKit
,在
MKMapViewDelegate
方法中,您可以对用户点击
MKAnnotationView
作出反应

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
  if let userLocation = view.annotation as? MKUserLocation {
    print("The user tapped on their user location annotation")
  } else {
    print("This is not the user location")
  }
}

假设您使用的是
MapKit
,在
MKMapViewDelegate
方法中,您可以对用户点击
MKAnnotationView
s作出反应

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
  if let userLocation = view.annotation as? MKUserLocation {
    print("The user tapped on their user location annotation")
  } else {
    print("This is not the user location")
  }
}