I can't seem to workout why the MKMapViewDelegate function is not being called when the annotation on the map is tapped.
Here is my code. Im expecting the very last function calloutAccessoryControlTapped to be called when the pin is tapped. But it isn't working.
class FindPeopleNearbyViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var locationManager : CLLocationManager!
@IBOutlet weak var mapView : MKMapView!
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
determineCurrentLocation()
}
func determineCurrentLocation()
{
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0] as CLLocation
let center = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.0025, longitudeDelta: 0.0025))
mapView.setRegion(region, animated: true)
// Drop a pin at user's Current Location
let myAnnotation: MKPointAnnotation = MKPointAnnotation()
myAnnotation.coordinate = CLLocationCoordinate2DMake(userLocation.coordinate.latitude, userLocation.coordinate.longitude);
myAnnotation.title = "My location"
mapView.addAnnotation(myAnnotation)
self.locationManager.stopUpdatingLocation()
}
internal func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
print("In annotation calloutAccessoryControlTapped")
}
Any help appreciate.