swift - openInMapsWithLaunchOptions 不起作用?

标签 swift ios8 mapkit

我正在传递 map 的选项,但这似乎对缩放级别没有任何作用??它保持相同的低缩放级别。 我错过了什么?

func openMapForPlace() {
    let regionDistance:CLLocationDistance = 10000
    var coordinates = CLLocationCoordinate2DMake(detailItem!.geoLatitude, detailItem!.geoLongitude)
    let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
    var options = [
        MKLaunchOptionsMapCenterKey: NSValue(MKCoordinate: regionSpan.center),
        MKLaunchOptionsMapSpanKey: NSValue(MKCoordinateSpan: regionSpan.span)
    ]
    var placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
    var mapItem = MKMapItem(placemark: placemark)
    mapItem.name = detailItem!.cityName
    mapItem.openInMapsWithLaunchOptions(options)
}

最佳答案

Apple 的文档没有提到它,但从测试来看,如果一个或多个 MKMapItem 似乎 openInMapsWithLaunchOptions() 似乎忽略了 MKLaunchOptionsMapSpanKey 选项> 已添加到 map 中。

以下代码按预期工作,在修改距离参数时正确调整 map 缩放(尝试使用 1000 和 10000000,以查看差异):

func openMapForPlace() {
    let regionDistance: CLLocationDistance = 10000000
    let coordinates = CLLocationCoordinate2DMake(40, 0)
    let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
    let options = [
        MKLaunchOptionsMapCenterKey: NSValue(MKCoordinate: regionSpan.center),
        MKLaunchOptionsMapSpanKey: NSValue(MKCoordinateSpan: regionSpan.span)
    ]

    MKMapItem.openMapsWithItems([], launchOptions: options)
}

但是,一旦将一个 MKMapItem 添加到 map 中,缩放就会停止工作。

func openMapForPlace() {
    let regionDistance: CLLocationDistance = 10000000
    let coordinates = CLLocationCoordinate2DMake(40, 0)
    let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
    let options = [
        MKLaunchOptionsMapCenterKey: NSValue(MKCoordinate: regionSpan.center),
        MKLaunchOptionsMapSpanKey: NSValue(MKCoordinateSpan: regionSpan.span)
    ]

    let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
    let mapItem = MKMapItem(placemark: placemark)
    mapItem.name = "Test"

    MKMapItem.openMapsWithItems([mapItem], launchOptions: options)
}

关于swift - openInMapsWithLaunchOptions 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28427557/

相关文章:

ios - Xcode 10 升级 : dyld library error on openssl. 框架/openssl

swift - 登录屏幕 SwiftUI

swift - 在 swift 中与 NMSSH 作斗争;错误-2、-9、-18、

swift - 如何在 swift 单元测试中验证方法是否在具体类中被调用

ios - 本地通知不适用于某些用户 (iOS 8)

ios - 无法将来自 geoCoder 的所有注释放在 map 上

ios - 无法看到位置 : [CLLocation]

ios8 - 如何在自适应 Storyboard中使用关闭 iPhone 弹出框

ios - 为什么我没有在 tableView 中获得不可见的节标题 View ?

ios - 为什么我无法自定义 MKAnnotationView?