Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LookAroundPreview for SwiftUI MapKit - does lookAroundViewer exist?

I'm having fun with SwiftUI's new MapKit capabilities, and I love how simple a LookAroundPreview is to create. But the documentation claims that there is a

.lookAroundViewer(isPresented: $isLookingAround, initialScene: lookAroundScene)

method that can be applied to existing views, and... well, it's not there - at least the compiler doesn't think so. To be clear, the documentation says:

To display a Look Around viewer a person can explore, apply a lookAroundViewer view modifier to a specific view, then add a control the user interacts with to display the Look Around viewer. In the following example, the lookAroundViewer view modifier observes a binding to Boolean value to determine whether to display the Look Around viewer.

Now, I have a static LookAroundPreview working (and man that's great, for so little effort), but I think the documentation is a little ahead of itself...

My question is "has .lookAroundViewer(isPresented: $isLookingAround, initialScene: lookAroundScene) actually been implemented in Xcode 15b3, and if so, how do I invoke it?".

Many thanks. Here's the working code...

    @State private var lookAroundScene: MKLookAroundScene?
    @State private var isLookingAround = false

    var body: some View {
        VStack {
            item.image
                .resizable()
                .aspectRatio(contentMode: .fill)
                //.lookAroundViewer(isPresented: $isLookingAround, initialScene: lookAroundScene) //<--- DOESN'T WORK
            if lookAroundScene.exists {
                Button(systemImage: "binoculars") { isLookingAround = true }
            }
        }
        .onAppear(perform: getLookAroundScene)
        .popover(isPresented: $isLookingAround) {
            LookAroundPreview(initialScene: lookAroundScene)
        }
    }
    
    private func getLookAroundScene() {
        lookAroundScene = nil
        Task {
            let request = MKLookAroundSceneRequest(coordinate: item.coordinate)
            lookAroundScene = try? await request.scene
        }
    }
like image 601
Grimxn Avatar asked Sep 13 '25 23:09

Grimxn


1 Answers

This seems to work now.

  • With your commented code, the LookaroundPreview opens in a mid-size view.
  • When the .lookAroundViewer line is uncommented, the view becomes fullscreen after touching. If you comment the second LookaroundPreview, the first one seems to miss an important initialization and the fullscreen preview appears but is empty.

Full code: https://gist.github.com/thadk/ea2e067b246b3bf7d96b94115da1f846

like image 51
thadk Avatar answered Sep 15 '25 14:09

thadk