SwiftUI Map + Marker + AsyncImage Support

I would like to be able to use AsyncImage inside of a SwiftUI Map Marker like this:

Map(position: $cameraPosition) {
    Marker(coordinate: coord) {
        AsyncImage(url: url)
    }
}

But when I try to do this I get one of two outcomes.

The first outcome I've seen is a crash like this:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x20)

The second possible outcome I've seen is that the image doesn't load but just has a blank placeholder like this:

I also tried creating a custom View that takes the url, downloads the data asynchronously, converts the data to a UIImage, sets the UIImage to a @State variable and then uses the Image(uiimage:) SwiftUI view but I got the same results.

Has anyone else gotten something like this working?

Answered by DTS Engineer in 799170022

@niclego Please use an Annotation to display a customizable annotation instead of a Marker.

Accepted Answer

@niclego Please use an Annotation to display a customizable annotation instead of a Marker.

Thank you so much for the reply! that worked.

SwiftUI Map + Marker + AsyncImage Support
 
 
Q