首页 > 解决方案 > iOS SwiftUI 上的 Mapbox 自动完成功能

问题描述

我正在开发一个基于 swift UI 的 iOS 应用程序。我想在其中拥有 Mapbox 自动完成功能。我尝试集成mapbox-search-SDK,但它似乎不支持 swift UI。

有什么我可以做的吗?这有可能吗?我也不可能恢复到另一个地图提供商。提前致谢。

标签: iosswiftuisdkmapboxmapbox-ios

解决方案


Mapbox 搜索 ui 在 UIKit 中完成,您可以使用or包装任何UIViewor 。UIViewControllerUIViewRepresentableUIViewControllerRepresentable

这是一个例子:

struct SearchControllerView: UIViewControllerRepresentable {
    typealias UIViewControllerType = MapboxSearchController

    func makeUIViewController(context: Context) -> MapboxSearchController{
        MapboxSearchController()
    }
    func updateUIViewController(_ uiViewController: MapboxSearchController, context: Context) { }
}

struct SearchControllerView_Previews: PreviewProvider {
    static var previews: some View {
        SearchControllerView()
    }
}

推荐阅读