2

When I press my button, I want to add an annotation to my mapview.

   let annotation = MKPointAnnotation()

    annoation.coordinate = (myrightCoordinates)

    let annoationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "ident")
    annoationView.image = UIImage(named: "single_base")

    mapView.addAnnotation(annoationView.annotation!)

My annoation appears, but not the image. What's wrong? The image name is correct, I check this minimum five times -.- I googled a lot and found everytime snippets like that. I want to solve that without CustomAnnotationClass or something like this.

Thanks for help :)

kuzdu
  • 7,124
  • 1
  • 51
  • 69

1 Answers1

0

// i think it will help for you.

let annotation = MKPointAnnotation()

annoation.coordinate = (myrightCoordinates)

let annoationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "ident")
annoationView.tag = 111
mapView.addAnnotation(annoationView.annotation!)
// need to give tag value if you have multiple annotations 
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
let pinImageAnnotation: MKAnnotationView = MKAnnotationView(annotation:annotation, reuseIdentifier:"pinImageAnnotation")
if annotation.tag == 111 {
    pinImageAnnotation.image = UIImage(named: "single_base")
}
return pinImageAnnotation
}
Satyanarayana
  • 1,059
  • 6
  • 16
  • thanks for the fast answer... my mistake was another. I had a spelling mistake with my identifier. – kuzdu May 10 '16 at 14:17
  • 1
    okay , but if you have diffrent types of annotations then you need to put condition with tag value.... that is only iam trying to say. – Satyanarayana May 10 '16 at 14:19