ImageRenderer fails to render maps

The new ImageRenderer in SwiftUI is really great and should help me to remove some custom code I've had to write in the past.

I've noticed that when used to capture a view that contains a map view, the map is replaced with a 'no entry' sign 🚫

Is this intentional?

Here's some sample code to replicate the issue: https://gist.github.com/shaundon/282cf7ff276093681a1c246ae318c9d4

Post not yet marked as solved Up vote post of shaundon Down vote post of shaundon
1k views

Replies

I have a similar problem but I'm using a UIViewControllerRepresentable, UIViewController and a UIHostingController in my (otherwise SwiftUI)-view hierarchy, which is rendered with the same yellow/red "no entry" sign. I don't know yet which of these UIKit-brigdes causes the issue, but I guess MapKit in SwiftUI uses a similar brigde under the hood, so maybe it's related.

  • Not sure if this will help your specific use case, but I have a workaround for creating images that include maps. The developer forum won't let me link to my blog, but if you search online for 'swiftui create image from view codakuma' it should be at the top of the results.

    It's quite hacky (which is why I'd like to replace it with ImageRenderer) but it works by capturing a screenshot of the entire screen, then cropping it to only include the part of the view you wish to capture.

Add a Comment