无法将SDK与SwiftUI一起使用以居中

问题描述

我正在尝试使用UIViewRepresentable将Google Map包装在SwiftUI视图内。我正在努力编码要使地图以其为中心的特定点(PNC公园),但是地图结果以该点的南部和东部为中心(约半英里)。可能与使用.zero帧初始化地图有关吗?

struct MapView: UIViewRepresentable {
    
    public var workoutLocations = RandomLocations().getMocklocationsFor(itemCount: 200)
    
      let latitude: CLLocationdegrees = 40.446855
      let longitude: CLLocationdegrees = -80.005666
    
    func makeUIView(context: Context) -> GMSMapView {
        
        let location = CLLocation(latitude: latitude,longitude: longitude)
        let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude,longitude: location.coordinate.longitude,zoom: 16.0)
        let mapView = GMSMapView.map(withFrame: CGRect.zero,camera: camera)
         mapView.mapType = .satellite
        
        return mapView
    }
    
    func updateUIView(_ mapView: GMSMapView,context: Context) {
    
     let location = CLLocation(latitude: latitude,longitude: longitude)
      
        mapView.animate(toLocation: location.coordinate)
    }
}

struct MapView_Previews: PreviewProvider {
    static var previews: some View {
        MapView()
    }
}

 var body: some View {
        
        NavigationView {
            ScrollView {
                vstack(alignment: .leading)  {
                    Text("Workout")
                        .font(.largeTitle)
                        .fontWeight(.bold)
                        .padding(.leading)
                    vstack(alignment: .center)  {
                        MapView()
                            .padding(.horizontal)
                            .edgesIgnoringSafeArea(.top) //remove?
                            .frame(height: 300)
                        RingView()
                        ScrollView(.horizontal) {
                        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)