gpt4 book ai didi

swift - openInMapsWithLaunchOptions 不起作用?

转载 作者:IT王子 更新时间:2023-10-29 05:43:33 24 4
gpt4 key购买 nike

我正在传递 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com