作者:额外的房间 | 来源:互联网 | 2023-05-22 17:16
1> Eneko Alonso..:
Apple的文档没有提到它,但是从测试来看,似乎openInMapsWithLaunchOptions()
忽略了MKLaunchOptionsMapSpanKey
如果将一个或多个MKMapItem
添加到地图中的选项.
以下代码按预期工作,修改距离参数时正确调整地图缩放(尝试使用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
添加到地图中,缩放就会停止工作.
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)
}