我传递了地图的选项,但这似乎没有对缩放级别做任何事情?它保持相同的低缩放级别。 我错过了什么?
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)
}
答案 0 :(得分:6)
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)
}