MKMapSnapshotter结果的边界框坐标

时间:2016-01-06 03:16:22

标签: 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
    }
}

我想知道的是生成图像的NE和SW角的精确坐标。这可能吗?是基于1000米距离的一些简单数学的情况,还是快照不是那么精确?

1 个答案:

答案 0 :(得分:1)

原来它只需要一些简单的数学:

    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)")
}