Posts

Post not yet marked as solved
3 Replies
1.9k Views
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.
Posted
by macmac72.
Last updated
.
Post not yet marked as solved
3 Replies
829 Views
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!
Posted
by macmac72.
Last updated
.
Post not yet marked as solved
1 Replies
1.1k Views
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!
Posted
by macmac72.
Last updated
.
Post not yet marked as solved
1 Replies
544 Views
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), ] }
Posted
by macmac72.
Last updated
.