I've tow UIViewControllers the first one displays an MKMapKitView with annotations and the user's current location and in the second viewController I'll be constructing the annotations that will be displayed to the first viewController.
I found out that if the user's location and the annotation are the same the mapView will only display the user's current location.
Here's my code to create an annotation:
func addAnnotiation(for locationCoordinate: CLLocationCoordinate2D) {
let annotationPoint = MKPointAnnotation()
annotationPoint.coordinate = locationCoordinate
mapView.addAnnotation(annotationPoint)
}
My MKMapViewDelegate
method:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "Annotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView!.canShowCallout = true
} else {
annotationView!.annotation = annotation
}
return annotationView
}
How can I solve this problem so if the annotation and the user's location are the same it will show the annotation also and not only the user's current location?