Я пытаюсь поместить пользовательское изображение на MKPointAnnotation
с заголовком.Ниже приведен код, который я имею в виду!
расширение ViewController: MKMapViewDelegate {
class myAnnotation: MKPointAnnotation {
var objectId:String = ""
var myImage:String = ""
}
//annotation for the points
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard annotation is myAnnotation else { return nil }
let myAnnotation = annotation as! myAnnotation
let identifier = "annotationView"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
print (myAnnotation.myImage)
if annotationView == nil {
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
}
//Pin with Title
if annotation.title == "fire" {
annotationView?.image = UIImage(named: "fire")
} else if annotation.title == "water"{
annotationView?.image = UIImage(named: "water")
}
return annotationView
}
func addStickForDanger(_ title:String, report:Reports){
let droPin = myAnnotation()
if (report.type!).boolValue {
droPin.title = "fire"
} else {
droPin.title = "water"
}
droPin.coordinate = CLLocationCoordinate2DMake(CLLocationDegrees(truncating: report.lat!), CLLocationDegrees(truncating: report.lon!))
droPin.objectId = report.objectId!
myMap.addAnnotation(droPin)
}
Нет ошибок, но просто он показывает обычный вывод.