【问题标题】:How to add a customized InfoWindow to markers in google-maps swift ui?如何将自定义的 InfoWindow 添加到 google-maps swift ui 中的标记?
【发布时间】:2021-05-28 23:59:45
【问题描述】:

我试图在 SwiftUi 中创建如下视图,但没有成功Customized info window swift ui

【问题讨论】:

  • 请为您的问题添加更多详细信息。添加您的代码,您遇到了什么错误,具体是什么不起作用等等。
  • 嗨,托德,感谢您的评论,问题是我尝试了几种方法,但没有得到我想要的结果,我没有收到任何错误,现在我删除了所有的代码没有给我想要的结果,你能检查一下这张图片,然后告诉我这个视图 Image 是否可以在 swiftui 中使用

标签: swiftui google-maps-markers infowindow


【解决方案1】:

由于这个问题没有太多细节,我将不做一些假设。首先,我假设您通过 UIViewControllerRepresentable 调用 MapView。

我对 Google Maps SDK 不太熟悉,但这可以通过 GMSMapViewDelegate 方法实现。实现正确的GMSMapViewDelegate 方法后,您可以使用 ZStacks 呈现您想要显示的图像。

例如:

struct MapView: UIViewControllerRepresentable {
    var parentView: ContentView
    func makeUIViewController(context: Context) {
        let mapView = GMSMapView()
        return mapView
    }
    func updateUIViewController(_ uiViewController: GMSMapView, context: Context) {
        
    }
    func makeCoordinator() -> Coordinator {
        return Coordinator(self)
    }
    class Coordinator: NSObject, GMSMapViewDelegate {
        var parent: MapView
        init(_ parent: MapView) {
            self.parent = parent
        }
        //Use the proper Google Maps Delegate method to find out if a marker was tapped and then show the image by doing: parent.parentView.isShowingInformationImage = true. 
    }
}

在您想要放置此 MapView 的 SwiftUI 视图中,您可以执行以下操作:

struct ContentView: View {
    @State var isShowingInformationImage = false
    var body: some View {
        ZStack {
            if isShowingInformationImage {
                //Call the View containing the image
            }
            MapView(parentView: self)
        }
    }
}

【讨论】:

    猜你喜欢
    • 2015-09-23
    • 1970-01-01
    • 2023-03-19
    • 2021-05-28
    • 2013-09-27
    • 2013-08-26
    • 2013-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多