Post

Replies

Boosts

Views

Activity

SwiftUI - Adjust Map() scale/zoom
Hi, I'm looking through SwiftUI Map for SwiftUI documentation (including IOS17 Beta) for way to adjust Map() scale, or zoom level, while simultaneously showing user's location and heading, for which I'm doing this @State var position = MapCameraPosition = .userLocation(followsHeading: true, fallback: .automatic) Map(position: $position) It does not appear to be possible so am looking for confirmation. Thanks everyone.
3
1
2.9k
Jul ’23
Adjust Map zoom level according to speed
Hi, I want Map() zoom level adjusted according to speed of the user. I'm currently using the following to initialize Map position: @State private var position: MapCameraPosition = .userLocation(followsHeading: true, fallback: .automatic) var body: some View { Map(position: $position) {...} } I get speed from CoreLocationl. How can I adjust zoom level, or camera position, to accomplish this? Thanks!
3
0
970
Jul ’23
Error when displaying Map() Annotation but not Marker
This code produces error "Publishing changes from within view updates is not allowed, this will cause undefined behavior." when displaying Annotation, but not when displaying Marker. I'd like to understand why and so far have not figured it out. import SwiftUI import MapKit struct ContentView: View { @StateObject var annotationViewModel = AnnotationViewModel() @State private var position: MapCameraPosition = .automatic var body: some View { Map(position: $position) { ForEach(annotationViewModel.annotations, id: \.self) { result in // Marker(result.title!, systemImage: "t.circle.fill", coordinate: result.coordinate) Annotation(result.title!, coordinate: result.coordinate) { Image(systemName: "t.circle.fill") } } } .mapStyle(.standard(elevation: .flat)) } } class MyAnnotation: NSObject, Identifiable { let id: UUID let title: String? let coordinate: CLLocationCoordinate2D init(id: UUID, title: String?, coordinate: CLLocationCoordinate2D) { self.id = id self.title = title self.coordinate = coordinate } } extension CLLocationCoordinate2D { static let ch = CLLocationCoordinate2D(latitude: 43.653734011477184, longitude: -79.38415146943686) } class AnnotationViewModel: NSObject, ObservableObject { @Published var annotations = [ MyAnnotation(id: UUID(), title: "CITY HALL", coordinate: .ch), ] }
1
0
593
Jun ’23
Explain Map() position
Hi, Can someone explain how the Map() position should work? struct ContentView: View { @State private var position: MapCameraPosition = .userLocation(followsHeading: true, fallback: .automatic) var body: some View { Map(position: $position) { UserAnnotation() } } } I was expecting the map to zoom in to users location but it shows the map zoomed out to the max instead. Location is authorized. I've also added the location button. .mapControls { MapUserLocationButton() } Pressing it zooms in to the user's location without issues. Thanks!
1
4
1.3k
Jun ’23