ios - MKMapSnapshotter 结果的边界框坐标

标签 ios mkmapview

我正在使用 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/

相关文章:

objective-c - 如何在 View 加载时显示 map View 标注

ios - MKMapCamera 的高度是如何计算的?

ios - SKAction 序列是否真的等到 Action 结束?

ios - Xcode 8.1 目标包含使用旧版本的 swift 开发的源代码

ios - 委托(delegate)按钮单击在 tableview 单元格中不起作用

iphone - 在单例中设置字典导致 EXC_BAD_ACCESS

iphone - 有没有办法旋转 MKMapView 并仍然显示 Google Logo ?

ios - 保留分配和初始化计数

ios - 如何通过协议(protocol)展示 View ?

swift - 自动显示注释标题