【发布时间】:2020-02-06 16:15:23
【问题描述】:
这就是我如何初始化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 上尝试了所有解决方案。
我在location 中有lat 和lng - 检查。该函数被调用 - 检查。
我也试过self.view.layoutSubviews(),self.view.layoutIfNeeded(),还有map
【问题讨论】:
标签: ios swift xcode gmsmapview