我只是将GMSMapView添加到viewcontroller内的视图中,但未居中,因为CLLocation
中给出正确的坐标,蓝点出现在正确的位置,但是只是地图稍微向右下移不知道为什么。我尝试直接在启动应用程序后直接在首页中运行它,然后运行正常,但是当我展示我的VC时,地图发生了变化。请任何人帮忙。
仅当我显示ViewController时才发生这种情况
您可以看到正确的位置是蓝点即将出现的位置:
答案 0 :(得分:1)
我有同样的问题。对我有用的是将代码从viewDidLoad
移到viewDidAppear
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
mapView.camera = GMSCameraPosition.camera(withLatitude: LocationConstants.defaultLat, longitude: LocationConstants.defaultLong, zoom: 15.0)
}
足够有趣的是,同一代码在UIViewController
中的另一个viewDidLoad
中工作。
答案 1 :(得分:0)
尝试
let camera = GMSCameraPosition.camera(withLatitude:-33.8683, 经度:151.2086, 变焦:16) 让mapView = GMSMapView.map(withFrame:self.view.bounds,camera:camera)
让mapView = GMSMapView(frame:self.view.bounds)