Positioning with MapUserTrackingMode SwiftUI 2.0

Hello!) Tell me why the location display does not work in the simulator?And how to fix the problem?
Thanks!



Code Block
import SwiftUI
import MapKit
struct ContentView: View {
    @State private var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 34.002871, longitude: -118.157545), span: MKCoordinateSpan(latitudeDelta: 0.03, longitudeDelta: 0.03))
    @State private var trackingMode = MapUserTrackingMode.follow
    var body: some View {
        Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true, userTrackingMode: $trackingMode)
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}


I actually have this issue, but not only in the simulator. I think though that the simulator does not know your location, but you can simulate a location (using the location icon in the debug area).

Anyway, it seems that the initial setting of the trackingMode is changed by the Map view. Tracking is not active on the Map even though the @State variable used is set to .follow when initialised. I have created a button displaying if the trackingMode is .follow or not, and action code that toggles the value. When the Map is displayed, the value is not .follow. When toggled, the tracking on the Map view is activated.

When NOT displaying the Map view (it's inside another View in my case) the initial value of trackingMode is .follow. Which kind of proves that Map changed the value. I'm running iOS 14.1 and Xcode 12.1


can toggle it with a button, and when I do the tracking on the map is indeed activated.
Positioning with MapUserTrackingMode SwiftUI 2.0
 
 
Q