Title is pretty self explanatory. I've tried calling it in viewDidLayoutSubviews()
as suggested here but it's given me no joy.
Here is my code:
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)
}
I've figured out a fix so I'm putting it here in case someone else has this issue.
I changed from using mapView?.animate
to GMSCameraPosition.camera
and it seems to be working fine.
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)
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments