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

SwiftUI Map: is it possible to add an inset to the map visible rectangle?
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?
2
0
1.8k
Feb ’24
SwiftUI - Adjust Map() scale/zoom
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.
3
1
3.9k
Jan ’24
Can you make a Marker selectable?
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?
2
1
2.0k
Nov ’23
iOS17: Widget support for SwiftUI and MapKit
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!
1
0
986
Oct ’23
Mapkit SwiftUI add Polygon with 'thickness'
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
0
0
862
Sep ’23
User location undefined in SwiftUI Preview
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?
2
0
1.8k
Sep ’23
Adjust Map zoom level according to speed
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!
3
0
1.4k
Sep ’23
SwiftUI MapKit map style inconsistency
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.
0
0
867
Aug ’23
MapKit's UserAnnotation() fails with Error Domain=kCLErrorDomain Code=1 "(null)"
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.
1
1
1.5k
Aug ’23
Missing parameter error in the first couple of steps
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?
4
0
2.5k
Aug ’23
Tap on maps to get coordinates
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
3
1
3.9k
Aug ’23
Please explain how to use MapProxy and MapReader
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
2
1
894
Jul ’23
MapKit with vision
Does visionOS support mapkit?
Replies
2
Boosts
0
Views
1.8k
Activity
Nov ’24
SwiftUI Map: is it possible to add an inset to the map visible rectangle?
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?
Replies
2
Boosts
0
Views
1.8k
Activity
Feb ’24
SwiftUI - Adjust Map() scale/zoom
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.
Replies
3
Boosts
1
Views
3.9k
Activity
Jan ’24
Can you make a Marker selectable?
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?
Replies
2
Boosts
1
Views
2.0k
Activity
Nov ’23
iOS17: Widget support for SwiftUI and MapKit
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!
Replies
1
Boosts
0
Views
986
Activity
Oct ’23
Mapkit SwiftUI add Polygon with 'thickness'
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
Replies
0
Boosts
0
Views
862
Activity
Sep ’23
resource code for demo?
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.
Replies
0
Boosts
0
Views
487
Activity
Sep ’23
map kit dark mode
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
Replies
0
Boosts
0
Views
854
Activity
Sep ’23
Where may we find the source code for this cool map project?
I am sorry if this is well known to others, but I would like to work with it, and don't know how to find.
Replies
1
Boosts
0
Views
844
Activity
Sep ’23
User location undefined in SwiftUI Preview
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?
Replies
2
Boosts
0
Views
1.8k
Activity
Sep ’23
Adjust Map zoom level according to speed
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!
Replies
3
Boosts
0
Views
1.4k
Activity
Sep ’23
SwiftUI MapKit map style inconsistency
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.
Replies
0
Boosts
0
Views
867
Activity
Aug ’23
MapKit's UserAnnotation() fails with Error Domain=kCLErrorDomain Code=1 "(null)"
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.
Replies
1
Boosts
1
Views
1.5k
Activity
Aug ’23
Meet MapKit for SwiftUI Error
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!
Replies
2
Boosts
0
Views
689
Activity
Aug ’23
tap on map and get location
Will this version of MapKit allow you to tap on a map and get the location to say play a pin there? Thanks
Replies
4
Boosts
2
Views
2.4k
Activity
Aug ’23
Missing parameter error in the first couple of steps
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?
Replies
4
Boosts
0
Views
2.5k
Activity
Aug ’23
Tap on maps to get coordinates
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
Replies
3
Boosts
1
Views
3.9k
Activity
Aug ’23
Zoom into user's location when found
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.
Replies
0
Boosts
0
Views
691
Activity
Aug ’23
source code for Meet MapKit for SwiftUI
Where is the source code for Meet MapKit for SwiftUI video ?
Replies
2
Boosts
1
Views
1.7k
Activity
Jul ’23
Please explain how to use MapProxy and MapReader
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
Replies
2
Boosts
1
Views
894
Activity
Jul ’23