Переместите значок GMSMarker в верхнем левом углу представления - PullRequest
0 голосов
/ 05 февраля 2019

Название довольно понятно.Я пытался назвать его в 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)
}

1 Ответ

0 голосов
/ 09 февраля 2019

Я нашел исправление, поэтому выкладываю его здесь на случай, если у кого-то еще возникнет эта проблема.

Я перешел с использования mapView?.animate на GMSCameraPosition.camera и, похоже, работает нормально.

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)
}
...