Integrating MapView into SwiftUI
Maps UIKit SwiftUI
Integrating MKMapViews inside of SwiftUI turns out to be rather simple, all we need to do is to properly create a container using UIViewRepresentable. In today's lesson we'll go over some basic stacking techniques and how to put a MapView inside of SwiftUI as a layer. Enjoy.

Comments (1)
shivaskanthan
3 years ago
Using a similar function but I'm not getting the expected result. The map doesn't show the bay area. Thoughts? struct MapViewContainer: UIViewRepresentable { typealias UIViewType = MKMapView let mapView = MKMapView() func makeUIView(context: Context) -> MKMapView { let mapView = MKMapView() setupRegionForMap(withCoordinates: CLLocationCoordinate2D(latitude: 37.7776, longitude: -122.427290)) return mapView } func updateUIView(_ uiView: MKMapView, context: Context) { } func setupRegionForMap(withCoordinates coordinate: CLLocationCoordinate2D) { let coordinateSpan = MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1) let region = MKCoordinateRegion(center: coordinate, span: coordinateSpan) mapView.setRegion(region, animated: true) } }
shivaskanthan
3 years ago
Issue fixed. I made mistake by creating a local instance of MKMapView in the makeUIView function.
HELP & SUPPORT