给定一个特定区域,我想获得一张地图图像,我正在使用 Swift MKMapSnapshotter 进行操作。图像很受欢迎,但是当我使用该snapshot.point
功能根据角坐标找到正确的像素时,它并没有准确地给我图像的角,怎么会?
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))")
}
收到的结果(四舍五入以获得更好的可读性):
(802.0, 722.0)
point:(0, 101)
point:(802, 734)
预期结果:
(802.0, 722.0)
point:(0, **0**)
point:(**801**, **721**)