这就是我初始化map
-GMSMapView
class ViewController: UIViewController {
var map = GMSMapView()
override func viewDidLoad() {
super.viewDidLoad()
setupGoogleView()
}
private func setupGoogleView() {
guard let coordinates = getUserLocation() else { return }
let camera = GMSCameraPosition.camera(withLatitude: coordinates.latitude, longitude: coordinates.longitude, zoom: 16.0)
self.map = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
map.settings.tiltGestures = false
map.mapType = .satellite
map.delegate = self
map.frame = view.frame
self.view.addSubview(map)
}
}
当我从文件中的其他位置调用此函数时,问题就来了
private func animateTo(location: CLLocationCoordinate2D) {
DispatchQueue.main.async {
let cameraPosition = GMSCameraPosition(target: location, zoom: 20)
self.map.animate(toLocation: location)
self.map.animate(to: cameraPosition)
}
}
我正在尝试将相机重新定位到某些坐标,但是什么也没有发生。我在stackoverflow
和上尝试了所有解决方案google
。
我lat
和lng
在location
-检查。该函数称为-已选中。
我也试过self.view.layoutSubviews()
,self.view.layoutIfNeeded()
和也map
我设法解决这个问题:
self.view.subviews.forEach { (view) in
if let mapView = view as? GMSMapView {
// do update on mapView here
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句