【发布时间】:2019-06-29 16:54:42
【问题描述】:
标题是不言自明的。我已经尝试按照here 的建议在viewDidLayoutSubviews() 中调用它,但这并没有给我带来快乐。
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
locationManager.requestWhenInUseAuthorization()
mapView.mapType = .normal
mapView.settings.zoomGestures = true
mapView.settings.tiltGestures = true
mapView.settings.rotateGestures = true
mapView?.isMyLocationEnabled = true
locationManager.startUpdatingLocation()
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
locationManager.delegate = self
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(_ animated: Bool) {
if(locationManager.location != nil){
centerMapOnLocation(location: locationManager.location!)
}
}
func centerMapOnLocation(location: CLLocation)
{
let camera = GMSCameraPosition.camera(withLatitude: locationManager.location!.coordinate.latitude, longitude: locationManager.location!.coordinate.longitude, zoom: zoom)
mapView?.animate(to: camera)
}
【问题讨论】:
标签: swift google-maps cllocationmanager