Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select apple default points of interest

Tags:

ios

mapkit

I have a question regarding to the default points of interest.

I can show the default POIs using mapView.showsPointsOfInterest = true

But I cannot tap on /select those POIs (restaurant, hotel, etc ..). All I want is that when I tap on it, I can get its info (long/lat, name ...)

I tried different delegate methods, such as func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) and func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?but none of those give me the right result

Can anyone help me with it? Thanks :)

like image 211
Albert Avatar asked Oct 26 '25 05:10

Albert


1 Answers

Figured it out. You need to set a configuration on the mapView to make points of interest selectable

mapView.selectableMapFeatures = [.pointsOfInterest]

and then you can listen to when these points are selected by the user using the mapView delegate method

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    print("did select: \(view.description)")
}
like image 116
Tys Avatar answered Oct 27 '25 20:10

Tys