IOS SWIFT При нажатии на назад к текущему местоположению после увеличения или уменьшения Googlemap не будет увеличивать уровень масштабирования по умолчанию - PullRequest
1 голос
/ 06 февраля 2020

Я подписался на GoogleMaps SDK. Карта показывает хорошо. MyLocation, zoom-in, zoom-out - все работает хорошо. Проблема заключается в том, что когда я нажимаю кнопку «myLocation» после увеличения или уменьшения масштаба и перемещаюсь в другое место, карта go возвращается к моему местоположению, НО масштаб остается в качестве уровня увеличения или уменьшения. Он не возвращается к исходному уровню масштабирования. Мой код выглядит следующим образом:

//googleMap
var locationManager = CLLocationManager()
var currentLocation: CLLocation?
var mapView: GMSMapView!
var placesClient: GMSPlacesClient!
var zoomLevel: Float = 15.0

// An array to hold the list of likely places.
var likelyPlaces: [GMSPlace] = []

// The currently selected place.
var selectedPlace: GMSPlace?

override func viewDidLoad() {
    super.viewDidLoad()

    locationManager = CLLocationManager()
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestAlwaysAuthorization()
    locationManager.distanceFilter = 50
    locationManager.startUpdatingLocation()
    locationManager.delegate = self

    let camera = GMSCameraPosition.camera(withLatitude: 43.6532,
                                          longitude: 79.3832,
                                          zoom: zoomLevel)
    mapView = GMSMapView.map(withFrame: view.bounds, camera: camera)
    mapView.settings.myLocationButton = true
    mapView.settings.compassButton = true
    mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    mapView.isMyLocationEnabled = true

    // Add the map to the view, hide it until we've got a location update.
    view.addSubview(mapView)
    mapView.isHidden = true

    placesClient = GMSPlacesClient.shared()

}

В моем CLLocationManagerDelegate у меня есть:

 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location: CLLocation = locations.last!
print("Location: \(location)")

let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude,
                                      longitude: location.coordinate.longitude,
                                      zoom: zoomLevel)
mapView.camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude,
longitude: location.coordinate.longitude,
zoom: zoomLevel)

if mapView.isHidden {
  mapView.isHidden = false
  mapView.camera = camera
} else {
  mapView.animate(to: camera)
}

}
...