如何解决如何在 google-maps swift ui 中向标记添加自定义信息窗口?
我试图在 SwiftUi 中创建一个类似于 bellow 的视图,但没有成功Customized info window swift ui
解决方法
由于这个问题没有太多细节,我将放弃一些假设。首先,我假设您通过 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)
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。