Hi !
First I'm new in SwiftUI and Xcode so I don't know if I my code is very clean but I got the same problem and I find something.
import SwiftUI
import MapKit
struct MapView: View {
var landmark: Landmark
@State private var position: MapCameraPosition = .automatic
var body: some View {
Map(position: $position){
Marker(landmark.name, coordinate: landmark.locationCoordinate)
}
.onAppear {
let region = MKCoordinateRegion(
center: CLLocationCoordinate2D(
latitude: landmark.locationCoordinate.latitude,
longitude: landmark.locationCoordinate.longitude),
span: MKCoordinateSpan(
latitudeDelta: 1,
longitudeDelta: 1)
)
position = .region(region)
}
}
}
struct MapView_Previews: PreviewProvider {
static var landmarks = ModelData().landmarks
static var previews: some View {
MapView(landmark: landmarks[0])
}
}
By using this code in the MapView File, you can change de latitudeDelta and the longitudeDelta that make the zoom in(lower value) or Zoom out (higher value).
Have a nice day !
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: