MKMapSnapshotter doesn't return exact region

163 Views Asked by At

Given a specific region, I want to get a map image, which I am doing with the Swift MKMapSnapshotter. The image is well received, however when I use the snapshot.point function to find the right pixel based on corner coordinates, it's not exactly giving me the corner of the image, how come ?

    let region = myMap.region
    let options = MKMapSnapshotter.Options()
    options.size = myMap.frame.size
    options.region = region
    var snapshotter = MKMapSnapshotter(options: options)
  
    snapshotter.start { [self] snapshot, error in
            guard let snapshot = snapshot else {
                print("Snapshot error: \(error!)")
                return
            }
            let corner1=CLLocationCoordinate2D(latitude: region.center.latitude-region.span.latitudeDelta/2, longitude: region.center.longitude-region.span.longitudeDelta/2)
            let corner2=CLLocationCoordinate2D(latitude: region.center.latitude+region.span.latitudeDelta/2, longitude: region.center.longitude+region.span.longitudeDelta/2)

            print(snapshot.image.size)
            print("point:\(snapshot.point(for: corner1))")
            print("point:\(snapshot.point(for: corner2))")
    }

Received result (rounded for better readability):

(802.0, 722.0)
point:(0, 101) 
point:(802, 734)

Expected result:

(802.0, 722.0)
point:(0, **0**) 
point:(**801**, **721**)
0

There are 0 best solutions below