Meet MapKit for SwiftUI

RSS for tag

Discuss the WWDC23 Session Meet MapKit for SwiftUI

View Session

Posts under wwdc2023-10043 tag

33 Posts
Sort by:
Post not yet marked as solved
0 Replies
396 Views
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
Posted
by
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
Post not yet marked as solved
3 Replies
1.2k Views
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?
Posted
by
Post not yet marked as solved
0 Replies
697 Views
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
Posted
by
Post not yet marked as solved
1 Replies
533 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
Post not yet marked as solved
4 Replies
1.7k Views
Will this version of MapKit allow you to tap on a map and get the location to say play a pin there? Thanks
Posted
by
Post not yet marked as solved
4 Replies
1.5k Views
Hello, I'm following along with this tutorial, and am getting this error on the first steps of the video: Missing argument for parameter 'mapRect' in call Here is my code: import SwiftUI import MapKit struct ContentView: View { var body: some View { Map() } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } Is the creator of the video somehow using a different version of the MapKit API than me? As far as I can tell, I am fully up-to-date. I'm on Ventura 13.4 using Xcode 14.3.1. I'm new to developing for Apple platforms, so maybe there's something obvious that I'm missing here?
Posted
by
Post not yet marked as solved
0 Replies
715 Views
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.
Posted
by
Post not yet marked as solved
2 Replies
2k Views
Hey guys, I recently started using Swiftui and would like to make a small app for my dad to use as a travel journal as my first project. He can create trips and then create multiple steps in a trip. When creating a step he should be able to set a location. Finding the location from the user is no problem. But now I also want to have the function to tap on the map and set a pin at a random location to get the coordinates (like google maps for example). Unfortunately I can't figure out from the documentation if there is a simple way to do this. import SwiftUI import MapKit struct StepLocationView: View { @EnvironmentObject var locationManagement: LocationDataManager @State private var position: MapCameraPosition = .automatic var body: some View { VStack { Map(position: $position) { UserAnnotation() } .navigationTitle("Search your location") .navigationBarTitleDisplayMode(.inline) .toolbarBackground(.visible, for: .navigationBar) .toolbarBackground(.ultraThinMaterial, for: .navigationBar) .edgesIgnoringSafeArea(.bottom) .onAppear{ position = .region(locationManagement.region) } .mapStyle(.standard(elevation: .realistic)) .mapControls { MapUserLocationButton() MapPitchButton() } } .background(Color.white) } } import SwiftUI import MapKit class LocationDataManager : NSObject, ObservableObject { @Published var location: CLLocation? @Published var region = MKCoordinateRegion() private let locationManager = CLLocationManager() override init() { super.init() locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.distanceFilter = kCLDistanceFilterNone locationManager.requestWhenInUseAuthorization() locationManager.startUpdatingLocation() // info.plist has to be updated locationManager.delegate = self } } extension LocationDataManager: CLLocationManagerDelegate { func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { guard let location = locations.last else { return } self.location = location self.region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude), latitudinalMeters: 5000, longitudinalMeters: 5000) }; } I really appreciate your help, Marius
Posted
by
Post marked as solved
1 Replies
930 Views
In the initial Xcode 15/iOS 17 Beta selecting a Marker would give a visible indication that the marker was selected without setting the selection. This is the code I used. struct ContentView: View { let location = CLLocationCoordinate2D(latitude: 37.0, longitude: -122.0) @State private var position: MapCameraPosition = .automatic @State private var selectedItem: MKMapItem? var body: some View { VStack { Text(selectedItem == nil ? "Nothing Selected" : selectedItem?.name == nil ? "No name" : selectedItem!.name!) .bold() .padding() Map(position: $position, selection: $selectedItem) { Marker("Marker", coordinate: location) .tag(1) .tint(.red) } } .padding() } } I submitted feedback and things changed in Beta 3. Now I can not select the Marker. That's not the direction I'd hoped to see. Am I doing something wrong or is there no way to select a Marker placed on a map?
Posted
by
Post not yet marked as solved
1 Replies
670 Views
I suspect MapReader may open the door to effectively track annotation coordinates as they are being dragged in Map. Similar to existing capabiltiies in MKMapView. I see that MapProxy contains a function called coordinatesFrom. Please provide a sample or any level of documentation that will explain how to properly instrument these with a Map. Particulary how to take advantage of this new function in MapProxy. https://developer.apple.com/documentation/mapkit/mapproxy/4278697-converttocoordinate Thank you
Posted
by
Post not yet marked as solved
3 Replies
790 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
Post not yet marked as solved
1 Replies
773 Views
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).
Posted
by