呈现viewController

时间:2018-08-01 01:13:51

标签: swift xcode google-maps storyboard

我只是将GMSMapView添加到viewcontroller内的视图中,但未居中,因为CLLocation中给出正确的坐标,蓝点出现在正确的位置,但是只是地图稍微向右下移不知道为什么。我尝试直接在启动应用程序后直接在首页中运行它,然后运行正常,但是当我展示我的VC时,地图发生了变化。请任何人帮忙。

仅当我显示ViewController时才发生这种情况

您可以看到正确的位置是蓝点即将出现的位置:

2 个答案:

答案 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)