Post

Replies

Boosts

Views

Created

Random Look Around Coordinates
I want to generate randomised MKLookAroundScene for my world exploration app (think geogussr functionality). How can i achieve that with MapKit? I have tried struct LookAroundView: View { @State private var lookAroundScene: MKLookAroundScene? @State private var yOffset: CGFloat = 0 func generateRandomCoordinate() { let minLatitude = -90.0 let maxLatitude = 90.0 let minLongitude = -180.0 let maxLongitude = 180.0 let randomCoordinate = CLLocationCoordinate2D( latitude: Double.random(in: minLatitude...maxLatitude), longitude: Double.random(in: minLongitude...maxLongitude) ) checkLookAroundAvailability(coordinate: randomCoordinate) } func checkLookAroundAvailability(coordinate: CLLocationCoordinate2D) { Task { let request = MKLookAroundSceneRequest(coordinate: coordinate) if let scene = try? await request.scene { DispatchQueue.main.async { self.lookAroundScene = scene } } else { generateRandomCoordinate() } } } var body: some View { Group { if let scene = lookAroundScene { LookAroundPreview(initialScene: scene) } else { Button(action: { generateRandomCoordinate() }) { Text("Generate Random Coordinate") } .offset(y: yOffset) } } } } but it didn't work. I put the yOffset change there to debug, and it seems that self.lookAroundScene = scene never gets executed. If there are any other options, please let me know!
1
1
828
Nov ’23
MapKit hide the current location label at the bottom of the Look Around View
I want to hide the bottom location label of the look around view. I'm using a LookAroundPreview to display it in the view, because if i used the controller, it will return a NSView instead of a View.
Replies
0
Boosts
1
Views
544
Activity
Nov ’23
Random Look Around Coordinates
I want to generate randomised MKLookAroundScene for my world exploration app (think geogussr functionality). How can i achieve that with MapKit? I have tried struct LookAroundView: View { @State private var lookAroundScene: MKLookAroundScene? @State private var yOffset: CGFloat = 0 func generateRandomCoordinate() { let minLatitude = -90.0 let maxLatitude = 90.0 let minLongitude = -180.0 let maxLongitude = 180.0 let randomCoordinate = CLLocationCoordinate2D( latitude: Double.random(in: minLatitude...maxLatitude), longitude: Double.random(in: minLongitude...maxLongitude) ) checkLookAroundAvailability(coordinate: randomCoordinate) } func checkLookAroundAvailability(coordinate: CLLocationCoordinate2D) { Task { let request = MKLookAroundSceneRequest(coordinate: coordinate) if let scene = try? await request.scene { DispatchQueue.main.async { self.lookAroundScene = scene } } else { generateRandomCoordinate() } } } var body: some View { Group { if let scene = lookAroundScene { LookAroundPreview(initialScene: scene) } else { Button(action: { generateRandomCoordinate() }) { Text("Generate Random Coordinate") } .offset(y: yOffset) } } } } but it didn't work. I put the yOffset change there to debug, and it seems that self.lookAroundScene = scene never gets executed. If there are any other options, please let me know!
Replies
1
Boosts
1
Views
828
Activity
Nov ’23