Demo.swift
ContentView.swift
App.swift
import MapKit
func openDirections() {
let dest = MKMapItem(
placemark: MKPlacemark(
coordinate: .init(latitude: 37.3349, longitude: -122.0090)
)
)
dest.name = "Apple Park"
dest.openInMaps(
launchOptions: [
MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving
]
)
}
import SwiftUI
struct ContentView: View {
var body: some View {
Button("Open Directions") { openDirections() }
.padding()
}
}
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup { ContentView() }
}
}