我正在传递地图选项,但这似乎与缩放级别没有任何关系?它保持相同的低缩放级别.
我错过了什么?
我错过了什么?
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选项.
原文链接:https://www.f2er.com/swift/319423.html以下代码按预期工作,修改距离参数时正确调整地图缩放(尝试使用1000和10000000,以查看差异):
func openMapForPlace() { let regionDistance: CLLocationDistance = 10000000 let coordinates = CLLocationCoordinate2DMake(40,0) let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates,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,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) }