2
私は、地図上の2本の異なるピンを使用しようとしています、これは私が持っているコードです:Mapに2つの異なるピンを追加するには? - スウィフト
func mapView (_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
{
//avoid for user location
if (annotation is MKUserLocation) {
return nil
}
let reuseId = "annId"
var anView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
if anView == nil {
if(annotation.subtitle! == "Offline"){
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView!.image = UIImage(named:"offIceCream.pdf")!
anView!.canShowCallout = true
}
if(annotation.subtitle! == "Online"){
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView!.image = UIImage(named:"onIceCream.pdf")!
anView!.canShowCallout = true
}
} else {
anView!.annotation = annotation
}
return anView
}
問題は、それが、注釈の字幕に応じて、正しいアイコンを設定していないことです。何らかの理由で時には正しく動作し、時には逆の方法で動作します(オフラインアノテーションとその逆のオンラインアイコンを設定します)。なぜこれが起きているのか?
ありがとうございます!