I am trying to create a map snapshot, using MKMapSnapshotter that includes a MKMarkerAnnotationView. The issue I am facing is that the MKMarkerAnnotationView is being clipped.
I can see that the frame of my MKMarkerAnnotationView is 28*28, which seems to be too small.
My code:
I can see that the frame of my MKMarkerAnnotationView is 28*28, which seems to be too small.
My code:
Code Block swift if let image = snapshot?.image { /* Create the annotation */ let annotation = MKPointAnnotation() annotation.coordinate = center /* Create the annotation view */ let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: nil) annotationView.glyphImage = UIImage(named: "mappin") annotationView.isSelected = true /* annotationView.frame would show the width and height being 28 */ /* Start the context */ UIGraphicsBeginImageContextWithOptions(image.size, true, image.scale) /* Draw the image from the MKMapSnapshotter in the context */ image.draw(at: CGPoint(x: 0, y: 0)) /* Define the rect where the Annotation View should be rendered in */ let rect = CGRect(x: snapshot!.point(for: center).x, y: snapshot!.point(for: center).y, width: annotationView.frame.width, height: annotationView.frame.height) /* Draw the Annotation View in the context */ annotationView.drawHierarchy(in: rect, afterScreenUpdates: true) let finalImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() }