I'm building a navigation app and I want the map to follow the user's location and heading with a specific pitch (e.g. 60 degrees...) , similar to how Apple Maps looks during navigation, or Google.
The problem I have...
.userLocation(followsHeading:fallback:) has no parameters for pitch or distance. When you switch to it, the map follows the user correctly but always resets to a flat 0° pitch regardless of what was set before.
It would be awesome to have something like this, I have submitted a feedback to Apple
camera = .userLocation(
followsHeading: true,
distance: 800,
pitch: 60,
fallback: .automatic
)
The workaround is as follows...
Set the desired camera first, wait for the animation to complete, then switch to .userLocation which inherits the pitch and distance from whatever the map's current state is at that moment (crazy)...
camera = .camera(MapCamera(
centerCoordinate: location.coordinate,
distance: 800,
heading: location.course < 0 ? 0 : location.course,
pitch: 60
))
Task {
try? await Task.sleep(for: .seconds(5))
camera = .userLocation(followsHeading: true, fallback: .automatic)
}
Seeding the camera with the desired pitch and distance, then waiting 5 seconds before handing off to .userLocation. This works because .userLocation inherits the pitch from whatever the map's current camera state is at the moment of the switch. The delay gives the animation time to fully complete so the inherited values are correct
This is fragile...Is there a reliable, non-hacky way to set the initial pitch and distance when switching to .userLocation tracking programmatically? Or is this a MapKit limitation with no clean solution?
This pitch is kind of important and I don't know of any reliable way to achieve it. It's more of a safety feature, This navigation app is built specifically for truck drivers, and the angled view gives them a much better perspective of what's coming up ahead so they can position in the correct lane in time. The app is about 90% done and this is the last major thing I need to sort out

cameraPosition = .camera(MapCamera(centerCoordinate: location.coordinate, distance: 800, heading: location.course < 0 ? 0 : location.course, pitch: 60))where@State private var cameraPosition: MapCameraPosition = .camera(MapCamera(centerCoordinate: .init(latitude: 0, longitude: 0), distance: 800, heading: 0, pitch: 60))andMap(position: $cameraPosition) {...}.