El título es bastante autoexplicativo. Intenté llamarlo en viewDidLayoutSubviews() como se sugiere aquí , pero no me ha dado alegría.
Aquí está mi código:
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) }He descubierto una solución, así que la pongo aquí en caso de que alguien más tenga este problema.
Cambié de usar mapView?.animate a GMSCameraPosition.camera y parece estar funcionando bien.
func centerMapOnLocation(location: CLLocation) { let target = CLLocationCoordinate2D(latitude: locationManager.location!.coordinate.latitude, longitude: locationManager.location!.coordinate.longitude) mapView.camera = GMSCameraPosition.camera(withTarget: target, zoom: zoom) }