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
572 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
3 Replies
1.9k 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
1 Replies
909 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
2 Replies
495 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
0 Replies
483 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
1 Replies
1.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
1 Replies
793 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
0 Replies
439 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
0 Replies
401 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
1 Replies
541 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
435 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