import MapKit
func launchAppleMaps() {
//我的位置
let currentLocation: MKMapItem = MKMapItem.forCurrentLocation()
let toCoor:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 23.119229410848003, longitude: 113.33045341883421)
let toMKPlacemark: MKPlacemark = MKPlacemark.init(coordinate: toCoor, addressDictionary: nil)
let toLocation: MKMapItem = MKMapItem.init(placemark: toMKPlacemark)
toLocation.name = "去的地方";
let options: [String : Any] = [
// 导航模式
MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
// 地图样式
MKLaunchOptionsMapTypeKey: MKMapType.standard.rawValue,
// 显示交通
MKLaunchOptionsShowsTrafficKey: true
]
MKMapItem .openMaps(with: [currentLocation,toLocation], launchOptions: options)
}
更新了原文代码
参考: