我正在使用 MKMapSnapshotter
创建 MKMapView 的快照。这非常有效:
let centerCoordinate = CLLocationCoordinate2DMake(-33.367348, 115.653591)
options.region = MKCoordinateRegionMakeWithDistance(centerCoordinate, 1000, 1000)
options.mapType = .Standard
options.size = CGSizeMake(2000, 2000)
let snapshotter = MKMapSnapshotter(options: options)
snapshotter.startWithCompletionHandler { snapshot, error in
if let error = error {
print(error)
}
else if let snapshot = snapshot {
//process result
}
}
我想知道的是结果图像的东北角和西南角的确切坐标。这可能吗?这是基于 1000m 距离的一些简单数学计算的情况,还是快照不那么准确?
最佳答案
事实证明它只需要一些简单的数学运算:
func printTranslatedCoordinates(coordinate: CLLocationCoordinate2D, latitudeMetres: Double, longitudeMetres: Double) {
let region = MKCoordinateRegionMakeWithDistance(coordinate, latitudeMetres, longitudeMetres)
let span = region.span
let northLatitude = coordinate.latitude + span.latitudeDelta
let eastLongitude = coordinate.longitude + span.longitudeDelta
let southLatitude = coordinate.latitude - span.latitudeDelta
let westLongitude = coordinate.longitude - span.longitudeDelta
print("\(westLongitude) \(southLatitude) \(eastLongitude) \(northLatitude)")
}
关于ios - MKMapSnapshotter 结果的边界框坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34625045/