In iOS13, working with MapKit in SwiftUI required wrapping in a UIKit compatible view. It seems that Map was implemented as a native view of SwiftUI in iOS14. Here, I put the code of "View to display the location of Apple headquarters on the map".
Map view of Swift UI
import SwiftUI
import MapKit
struct MapView: View {
    @State var region = MKCoordinateRegion(
        center: CLLocationCoordinate2D(latitude: 37.3351, longitude: -122.0088),
        span: MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02))
        
    var body: some View {
        Map(coordinateRegion: $region)
    }
}
struct MapView_Previews: PreviewProvider {
    static var previews: some View {
        MapView()
    }
}

Recommended Posts