Meet MapKit for SwiftUI

RSS for tag

Discuss the WWDC23 Session Meet MapKit for SwiftUI

Posts under wwdc2023-10043 tag

33 Posts

Post

Replies

Boosts

Views

Activity

iOS 17 Map sits over TabView
I'm putting together a really simple demo/learning app to try out some of the new features of iOS 17, and I've found when adding a Map to an existing TabView, the map is extending itself over the tab, which is actually still visible and can be interacted with, but is basically hidden. There may be a modifier or something I'm missing to tell the map to stay in its frame, but I haven't found it. I have tried ones like safeAreaInsets, but that didn't seem to be right. Here's my super-simple view: TabView { Text("Not the map") .tabItem { Label("Not Map", systemImage: "person") } Map() .tabItem { Label("Map", systemImage: "map") } } And here's how it looks in the Simulator: I will file a feedback for this, but didn't want to too quickly assume it's a bug when it's just as likely I'm not doing something right (if not more so).
1
0
1.2k
Jul ’23
MapCircle not updating on center or radius change
Using Xcode 15.0 beta 4 I have MapCoordinate struct: private struct MapCoordinate: Equatable { let location: Location let latitude: Double let longitude: Double var coordinate: CLLocationCoordinate2D { return CLLocationCoordinate2D(latitude: latitude, longitude: longitude) } init?(location: Location) { guard let latitude = location.latitude, let longitude = location.longitude else { return nil } self.location = location self.latitude = latitude self.longitude = longitude } } mapCoordinate and radius state variables: @State private var mapCoordinate: MapCoordinate? @State private var radius: CLLocationDistance And a mapView: @ViewBuilder var mapView: some View { Map { if let mapCoordinate { let annotationTitle = radius.toMeasurement(unit: .meters, convertedTo: .kilometers) Annotation(annotationTitle, coordinate: mapCoordinate.coordinate) { Image(systemImage: .mapPinEllipse) .fontWeight(.semibold) } MapCircle(center: mapCoordinate.coordinate, radius: radius) .foregroundStyle(.teal.opacity(circleOpacity)) .stroke(.teal, lineWidth: circleStrokeLineWidth) } } .mapStyle(.standard(elevation: .realistic)) .animation(.easeInOut, value: mapCoordinate) } When updating mapCoordinate the Annotation will animate correctly to the new coordinates, but the MapCircle will not update or change scale for neither mapCoordinate or radius changes. Ideas?
0
0
890
Jul ’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.5k
Jun ’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
709
Jun ’23
Random error
Have a map. I have two pins. i have two buttons. When one button is pressed it goes to first pin. When second button is pressed it goes to second pin. The problem is if I move the map at all then press second button the first button vanishes and the map hasn’t moved - wonder if this is a bug. I can surely put the code
0
0
574
Jun ’23
iOS 17 Map sits over TabView
I'm putting together a really simple demo/learning app to try out some of the new features of iOS 17, and I've found when adding a Map to an existing TabView, the map is extending itself over the tab, which is actually still visible and can be interacted with, but is basically hidden. There may be a modifier or something I'm missing to tell the map to stay in its frame, but I haven't found it. I have tried ones like safeAreaInsets, but that didn't seem to be right. Here's my super-simple view: TabView { Text("Not the map") .tabItem { Label("Not Map", systemImage: "person") } Map() .tabItem { Label("Map", systemImage: "map") } } And here's how it looks in the Simulator: I will file a feedback for this, but didn't want to too quickly assume it's a bug when it's just as likely I'm not doing something right (if not more so).
Replies
1
Boosts
0
Views
1.2k
Activity
Jul ’23
MapCircle not updating on center or radius change
Using Xcode 15.0 beta 4 I have MapCoordinate struct: private struct MapCoordinate: Equatable { let location: Location let latitude: Double let longitude: Double var coordinate: CLLocationCoordinate2D { return CLLocationCoordinate2D(latitude: latitude, longitude: longitude) } init?(location: Location) { guard let latitude = location.latitude, let longitude = location.longitude else { return nil } self.location = location self.latitude = latitude self.longitude = longitude } } mapCoordinate and radius state variables: @State private var mapCoordinate: MapCoordinate? @State private var radius: CLLocationDistance And a mapView: @ViewBuilder var mapView: some View { Map { if let mapCoordinate { let annotationTitle = radius.toMeasurement(unit: .meters, convertedTo: .kilometers) Annotation(annotationTitle, coordinate: mapCoordinate.coordinate) { Image(systemImage: .mapPinEllipse) .fontWeight(.semibold) } MapCircle(center: mapCoordinate.coordinate, radius: radius) .foregroundStyle(.teal.opacity(circleOpacity)) .stroke(.teal, lineWidth: circleStrokeLineWidth) } } .mapStyle(.standard(elevation: .realistic)) .animation(.easeInOut, value: mapCoordinate) } When updating mapCoordinate the Annotation will animate correctly to the new coordinates, but the MapCircle will not update or change scale for neither mapCoordinate or radius changes. Ideas?
Replies
0
Boosts
0
Views
890
Activity
Jul ’23
Autorefresh MapPolyline when route data grows
Map(position: $position, selection: $selectedResult) { MapPolyline(coordinates: track).stroke(.blue, lineWidth: 5) } When the @State track: [CLLocationCoordinates] is growing with new data (new coordinates appended) how can we reach that Map and MapPolyline is automatically refreshed?
Replies
3
Boosts
2
Views
1.9k
Activity
Jul ’23
are draggable markers possible?
is it possible, to allow the user updating the marker position like with the MKMarkerAnnotationView.isDraggable attribute available in a MkMapView?
Replies
2
Boosts
2
Views
1.1k
Activity
Jul ’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!
Replies
1
Boosts
4
Views
1.5k
Activity
Jun ’23
following
I am flowing the code, but I have an error message coming when I code myself with Xcode for WWDC 23. The Section is Meet Mapkit for SwiftUI.
Replies
0
Boosts
0
Views
858
Activity
Jun ’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), ] }
Replies
1
Boosts
0
Views
709
Activity
Jun ’23
Download offline map available programmatically?
Subject says it all: is or will there be a way to download offline maps programmatically?
Replies
1
Boosts
0
Views
2k
Activity
Jun ’23
MKTileOverlay
Hi, Tile overlays, the method to use other sources than Apple's maps, are not covered (yet). What would be the best way of implementing them now, in SwiftUI with the new MapKit? Thanks -Werner
Replies
1
Boosts
3
Views
961
Activity
Jun ’23
When will mapkit for swiftui SDK be available to use in xcode?
I really would like to avoid installing any beta versions, when can i expect the SDK to be available and deployed for us to use?
Replies
1
Boosts
0
Views
902
Activity
Jun ’23
Random error
Have a map. I have two pins. i have two buttons. When one button is pressed it goes to first pin. When second button is pressed it goes to second pin. The problem is if I move the map at all then press second button the first button vanishes and the map hasn’t moved - wonder if this is a bug. I can surely put the code
Replies
0
Boosts
0
Views
574
Activity
Jun ’23
Mapkit for SwiftUI custom callouts
The new Mapkit for SwiftUI improvements are much welcomed. Are custom map callouts available? Thank you.
Replies
0
Boosts
0
Views
533
Activity
Jun ’23
Cluster Annotations
The new Map builder SwiftUI is awesome. Does it support cluster annotations? I have opened FB12244017. Thank you very much!
Replies
0
Boosts
2
Views
840
Activity
Jun ’23