当我按下按钮时,我想在地图视图中添加注释。
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或类似的东西的情况下解决这个问题。
感谢您的帮助:)
答案 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
}