在 MapBox SwiftUI 中使用自定义注释图像

Use Custom Annotation Image in MapBox SwiftUI

我最近学习了使用 MapBox 的 this tutorial 将 MapBox 集成到我的 SwiftUI 应用程序中的教程。我现在正在寻找自定义用于地图上注释标记的图像。有没有人这样做过或者愿意给出一个简短的例子来说明如何使用 MapBox 和 SwiftUI 来实现?我当前的代码看起来与上面的教程几乎相同。

非常感谢您的宝贵时间!

我最终弄明白了,所以我会post其他用户。

当前注释指南没有提供任何有关如何在 SwiftUI 中直接执行此操作的示例,但是,您可以使用一些内置函数来完成确切的任务。在原始文档中显示的 Coordinator class 中,您只需添加以下方法即可在每个注释处显示您想要的任何图像。

func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
            
    return MGLAnnotationImage(image: UIImage(named: "imageName")!, reuseIdentifier: "map-marker")
            
}