I am developing an app for chating, I have to display all friends on a Map with their image. Please provide guidance to implement it.
I have used following code...>
A swift4 version of Nitesh Borad
Answer:
func mapView(_ map: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationViewReuseIdentifier = "annotationViewReuseIdentifier"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationViewReuseIdentifier) as? MKAnnotationView
if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationViewReuseIdentifier)
}
// here you can assign your friend's image
annotationView?.image = UIImage(named: "friend_image.png")
annotationView?.annotation = annotation
// add below line of code to enable selection on annotation view
annotationView?.canShowCallout = true
return annotationView
}