首页 > 解决方案 > SwiftUI 中的 GMSMarker 点击事件

问题描述

我在 UiViewRepresentable 结构中使用了 makeUiView() 和 updateUiView() 方法来创建我的地图视图。

struct GoogleMapView: UIViewRepresentable {
    func updateUIView(_ uiView: GMSMapView, context: Context) {
        let marker : GMSMarker = GMSMarker()
        marker.position = CLLocationCoordinate2D(latitude: 20, longitude: 50);
        marker.map = uiView;
    } 

    func makeUIView(context: Context) -> GMSMapView {
        let camera = GMSCameraPosition.camera(withLatitude: 20, longitude: 50,zoom: 10)
        let mapView  = GMSMapView(frame: CGRect.zero, camera: camera)
        mapView.delegate = ViewController()
        return mapView
    }
}

如果我单击地图上的标记,我想导航到不同的视图。我发现我必须为此使用 GMSMapViewDelegate 和 mapView() 函数。但目前我没有在我的项目中使用任何 ValueControler。还有在哪里制作mapView.delegate = 自我?

标签: swiftgoogle-mapsswiftuiisoswiftui-navigationview

解决方案


推荐阅读