openInMapsWithLaunchOptions 不起作用?
openInMapsWithLaunchOptions not working?
我正在传递地图的选项,但这似乎对缩放级别没有任何作用??它保持相同的低缩放级别。
我错过了什么?
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
选项。
以下代码按预期工作,在修改距离参数时正确调整地图缩放(尝试使用 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)
}
我正在传递地图的选项,但这似乎对缩放级别没有任何作用??它保持相同的低缩放级别。 我错过了什么?
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
选项。
以下代码按预期工作,在修改距离参数时正确调整地图缩放(尝试使用 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)
}