Post

Replies

Boosts

Views

Activity

Reply to Adjust Map zoom level according to speed
I've found that using MapCameraBounds adjusts zoom level mapCameraBounds = MapCameraBounds(minimumDistance: minimumDistance, maximumDistance: maximumDistance) I now want to make the changes smooth and have thought of using .onChange(of:) and withAnimation, as follows: .onChange(of: locationManager.currentLocation?.speed) { oldValue, newValue in withAnimation(.spring(duration: 1.0)) { let speed = newValue ?? 0.0 if speed > 20 { minimumDistance = 5000.0 maximumDistance = 10000.0 } else { minimumDistance = 1000.0 maximumDistance = 2000.0 } mapCameraBounds = MapCameraBounds(minimumDistance: newValue, maximumDistance: maximumDistance) } } Map(position: $position, bounds: mapCameraBounds) But that doesn't work, zoom changes are not animated. Is there a proper way of doing this?
Jul ’23
Reply to Adjust Map zoom level according to speed
My previous attempt with MapCameraBounds() was not the correct one. There are at least two conflicting ways to set camera position. @State private var position: MapCameraPosition = .userLocation(followsHeading: true, fallback: .automatic) @State private var position: MapCameraPosition = .region(region: MKCoordinateRegion) The first one gives me user location and heading, the second one lets me specify region and zoom in/out (with animation). I've added MapUserLocationButton() to show user location/heading but its turned off as soon as MKCoordinateRegion updates. How do I combine these to get both effects? Thanks
Jul ’23