Reputation: 151
I am working with MapKit and I changed the Annotation´s image, but the problem is, the Userlocation (blue dot) also changed its picture (I didn't want that). How can I restore it back to normal. Also, I added a small button to the callout which (as you may have guessed) was added to my location and it was not supposed to be there. My code is the following...
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if !(annotation is MKUserLocation) {
print("annotation is MKUserLocation")
}
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "identifier")
if annotationView == nil{
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "identifier")
annotationView!.canShowCallout = true
annotationView!.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
let pinImg = UIImage(named: "curz")
let size = CGSize(width: 50, height: 50)
UIGraphicsBeginImageContext(size)
pinImg!.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
annotationView!.image = resizedImage
}
else {
annotationView!.annotation = annotation
}
return annotationView
}
//Var SelectedAnnotation
var anotacionSeleccionada : MKPointAnnotation!
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == view.rightCalloutAccessoryView {
anotacionSeleccionada = view.annotation as? MKPointAnnotation
performSegue(withIdentifier: "vista", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? ViewController {
destination.pin = anotacionSeleccionada
}
}
Upvotes: 0
Views: 38
Reputation: 38833
In your viewFor annotation
function add this row in the beginning:
if annotation is MKUserLocation {
return nil
}
Because you don´t want to do anything if it´s the MKUserLocation
.
Upvotes: 1