Post

Replies

Boosts

Views

Activity

Reply to Map in SwiftUI just wont follows users heading when first shown
I feel the pain. Here's what I've done to get the map oriented correctly the first time. First of all, you should introduce a @State.... @State private var position: MapCameraPosition = .automatic Then initialize the Map with a binding to the @State like this.... Map(position: $position) { The final piece is to add a .task view modifier to Map... .task { position = .userLocation(followsHeading: true, fallback: .automatic) } What this does is execute the statements at a slightly later time on the MainActor after the view appears. Apparently, the heading-following functionality isn't ready on initialization of BackgroundMapView or Map. By the time the Task completes, the app seems prepared and do the right thing. So your code should look something like this: @State private var position: MapCameraPosition = .automatic var body: some View { Map(position: $position) { // .... } .task { position = .userLocation(followsHeading: true, fallback: .automatic) } } Hope this works out.
Dec ’24