在IOS 13中,未推动ViewController时,Google Map相机位置未显示准确。均附有两个屏幕截图

问题描述 投票:0回答:1

我正在开发出租车应用程序,我想在这里展示并显示三个标记,但是相机位置始终在左上角,我必须滚动地图视图才能看到这些标记。已经尝试过这些事情。

  • 将我的代码放入viewwillappear和viewdidappear并将其从viewdidload中删除。
  • 2秒后将我所有的代码放入DispatchQueue中
  • 使用动画并增加/减少时间。

附带示例代码只是为了显示一个标记,当将视图控制器推入导航堆栈时,它可以正常工作。

 func testCode() {
    mapView.layoutIfNeeded()
   DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {

   let camera = GMSCameraPosition(latitude: 31.326137, longitude: 75.575520, zoom: 10)
        self.pickupMarker = GMSMarker()
        self.addMarkerOnMap(lat: "31.326137", long: "75.575520", img: #imageLiteral(resourceName: "drop-icon"), mapVieww: self.mapView,marker: &(self.pickupMarker), title: "Drop at", snippet:"Hello")
    CATransaction.begin()
    CATransaction.setValue(Int(1), forKey: kCATransactionAnimationDuration)
    self.mapView.animate(to: camera)
CATransaction.commit()
               })
}

Accurate Location when pushed

InAcurate camera position when presented

ios swift google-maps google-maps-markers ios13
1个回答
0
投票

我做了四件事来解决此问题。

  1. 首先在情节提要中的一个我想要我的地图视图的地方带一个容器,然后在课堂上做一个出口。
  2. 也从情节提要中删除mapview出口并删除mapview UIVIew。
  3. 以编程方式将GMSMapView作为子视图添加到容器(我要在其中显示地图的位置)。
  4. 在Dispatchqueue中的viewdidappear方法中添加代码,现在一切正常。
© www.soinside.com 2019 - 2024. All rights reserved.