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
1 Replies
771 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 alpennec.
Last updated
.
Post not yet marked as solved
3 Replies
1.6k 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 marked as solved
1 Replies
811 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 marchyman.
Last updated
.
Post not yet marked as solved
1 Replies
448 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 sofapps.
Last updated
.
Post not yet marked as solved
0 Replies
353 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 Woutster.
Last updated
.
Post not yet marked as solved
0 Replies
328 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.
Posted Last updated
.
Post not yet marked as solved
0 Replies
356 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 neffdsgn.
Last updated
.
Post not yet marked as solved
1 Replies
630 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 garbinato.
Last updated
.
Post not yet marked as solved
3 Replies
711 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
0 Replies
404 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 mylaluna.
Last updated
.
Post not yet marked as solved
1 Replies
805 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 mikemjc.
Last updated
.
Post not yet marked as solved
2 Replies
423 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 tboward.
Last updated
.
Post not yet marked as solved
4 Replies
1.5k 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 Tomha.
Last updated
.
Post not yet marked as solved
4 Replies
1.4k 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 Last updated
.
Post not yet marked as solved
2 Replies
1.8k 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 Last updated
.
Post not yet marked as solved
0 Replies
405 Views
Is there a way to zoom into user's location when the location is found? I am wondering if there is a helper method provided by SwiftUI Map.
Posted
by azamsharp.
Last updated
.
Post not yet marked as solved
1 Replies
602 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 Last updated
.