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
409 Views
I have viewed the WWDC video about MapKit in SwiftUI AWESOME! I want to work with that! I noticed that you can view the map at an angle, so that you can for instance look under a bridge. I saw in the video that it is possible to add a MapPolygon. But when the MapView apparently has a 3rd dimension ... is it possible to add a MapPolygon with a certain thickness? Or perhaps let a MapPolygon only occupy space from say 10 to 20 meters high? Thanks!! Wouter
Posted
by
Post not yet marked as solved
1 Replies
507 Views
Hi there, we're in the process of refactoring some portions of our widgets to add some new capabilities like interactivity. In the mean time, we're wondering if there is any support for native MapKit within Widget on iOS17. We tried a simple test, but seems that MapKit is still not available on Widgets. Is this correct? Am I missing something? Many thanks for your answer!
Posted
by
Post not yet marked as solved
0 Replies
379 Views
Thanks for posting the video of the changes made to MapKit. I'm trying to follow along just a little unsure of the code placement for the request route section. I'm looking around to see if you posted the code used in your demo but can't find it. Any chance you have it available.
Post not yet marked as solved
0 Replies
417 Views
Hi , i have been trying to find a solution to use mapkit in dark mode. I read documentation part and map view.mapkit.colorschemes.darkmode but I could not find any useful example for this. Thanks
Posted
by
Post not yet marked as solved
1 Replies
745 Views
In the wwdc2023-10043 session, the instructor adds a MapUserLocationButton towards the end, which seems to work fine in the SwiftUI Preview for him. However, when I follow this tutorial and add the very same button, I get a never-ending spinning wheel upon clicking it in SwiftUI Preview. I guess that the SwiftUI Preview cannot get a user location. I searched in various places whether I could set the user location, as possible in the simulator, but to no avail. In the Debug menu, there is a Simulate Location submenu, but it totally deactivated (greyed out). Does anyone know how to allow SwiftUI Preview to get an actual user location, i.e., either the one from my Mac or one that I could provide to the SwiftUI Preview simulator?
Posted
by
Post not yet marked as solved
1 Replies
1k Views
In UIKit, we can add an insets to a MKMapView with setVisibleMapRect to have additional space around a specified MKMapRect. It's useful for UIs like Apple Maps or FlightyApp (see first screenshot attached). This means we can have a modal sheet above the map but still can see all the content added to the map. I'm trying to do the same for a SwiftUI Map (on iOS 17) but I can't find a way to do it: see screenshot 2 below. Is it possible to obtain the same result or should I file a feedback for an improvement?
Posted
by
Post not yet marked as solved
0 Replies
460 Views
I am switchingt to the new WWDC 2023 SwiftUI map with user location and a few map annotations. I find if I use .mapStyle(.imagery(elevation: .flat)) as the map style, the map will be loaded with a reasonably zoomed area. However, if I use .mapStyle(.imagery(elevation: .realistic)) on the same map, the simulator will give me a view of the entire planet. I have to manually zoom in everytime to find the user location and annotations, which is not very convenient. This is the only map style configuration that does this. I am not very sure if this is a feature or a inconsistency bug. If this is a feature, I cannot see the purpose of it.
Posted
by
Post not yet marked as solved
2 Replies
474 Views
I keep receiving this error: Value of type 'MKDirections.Response?' has no member 'route' Here is my code: Task { let directions = MKDirections(request: request) let response = try? await directions.calculate() route = response.route.first } any pointers on how to fix? Thanks!
Posted
by
Post not yet marked as solved
1 Replies
879 Views
I replicated code in WWDC2023-10043: Meet MapKit for SwiftUI (https://developer.apple.com/videos/play/wwdc2023/10043/ ) and everything worked fine except showing user location with UserAnnotation() which starts at 23:24 of the presentation. Xcode console displays the following error: CLLocationManager(<CLLocationManager: 0x600000008630>) for <MKCoreLocationProvider: 0x600003014510> did fail with error: Error Domain=kCLErrorDomain Code=1 "(null)" The same error happens even with code as simple as the below: import SwiftUI import MapKit struct ContentView: View { var body: some View { Map() { UserAnnotation() } } } Error occurs with Preview, Simulator and iPhone device. Software being used are the latest beta versions: iOS 17 beta 5, Xcode 15 beta 6.
Posted
by
Post not yet marked as solved
3 Replies
1.8k 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
Post not yet marked as solved
0 Replies
555 Views
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?
Posted
by
Post not yet marked as solved
1 Replies
774 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
Post not yet marked as solved
3 Replies
791 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
671 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 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
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 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
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