-2

I do a app with MapKit and I want the user can select an annotation (clic on) and then open a new view controller.
I do it with the method :

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    performSegue(withIdentifier: "showClic", sender: nil)
}

But this code open the VC when there a cluster of annotation.
And I want to do when there is a cluster of annotation a zoom with the camera and open the VC only when only one annotation is selected.

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
CocoBalt
  • 1
  • 1

1 Answers1

0

func fitMapViewToAnnotaionList(annotations: [MKPointAnnotation], userLocation: CLLocationCoordinate2D) -> Void { let mapEdgePadding = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20) var zoomRect:MKMapRect = MKMapRectNull

    for index in 0..<annotations.count {
        let annotation = annotations[index]
        let aPoint:MKMapPoint = MKMapPointForCoordinate(annotation.coordinate)
        let rect:MKMapRect = MKMapRectMake(aPoint.x, aPoint.y, 0.1, 0.1)

        if MKMapRectIsNull(zoomRect) {
            zoomRect = rect
        } else {
            zoomRect = MKMapRectUnion(zoomRect, rect)
        }
    }

    let aPoint:MKMapPoint = MKMapPointForCoordinate(userLocation)
    let rect:MKMapRect = MKMapRectMake(aPoint.x, aPoint.y, 0.1, 0.1)

    if MKMapRectIsNull(zoomRect) {
        zoomRect = rect
    } else {
        zoomRect = MKMapRectUnion(zoomRect, rect)
    }
    mapView.setVisibleMapRect(zoomRect, edgePadding: mapEdgePadding, animated: true)
}