带图像的MKPointAnnotation,通过Button插入注释,图像不会显示

时间:2016-05-10 13:57:12

标签: ios swift image mapkit

当我按下按钮时,我想在地图视图中添加注释。

   let annotation = MKPointAnnotation()

    annoation.coordinate = (myrightCoordinates)

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

    mapView.addAnnotation(annoationView.annotation!)

我的出现了,但不是图像。怎么了?图像名称是正确的,我检查这至少五次--.-我google了很多,发现每次这样的片段。我想在没有CustomAnnotationClass或类似的东西的情况下解决这个问题。

感谢您的帮助:)

1 个答案:

答案 0 :(得分:0)

//我认为这会对你有所帮助。

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
}