(iOS Swift)Google Maps animateWithCameraUpdate不起作用

Bha*_*dy 1 google-maps ios swift

我正在使用iOS中的Google地图。我想为我的相机设置动画,使其显示所有必需的纬度,经度。我将这些位置存储在数组中(作为CLLocationCoordinate2D实例),并使用GMSCoordinateBounds类添加这些位置。这是我的代码:

        let bounds = GMSCoordinateBounds()
        bounds.includingCoordinate(firstLocation)
        bounds.includingCoordinate(lastLocation)
        let camUpdate = GMSCameraUpdate.fit(bounds, withPadding: 60)

        mMapView.camera = GMSCameraPosition.camera(withLatitude: firstLocation.latitude, longitude: firstLocation.longitude, zoom: 18)

        mMapView.animate(with: camUpdate)
Run Code Online (Sandbox Code Playgroud)

firstLocation和lastLocation具有正确的值,但相机未设置动画。我想念什么吗?

Bha*_*dy 6

非常愚蠢的错误。includesCoordinates函数返回GMSCoordinateBounds对象。我必须重新设置自身,这样它才能像这样工作:

bounds = bounds.includingCoordinate(firstLocation)

bounds = bounds.includingCoordinate(lastLocation)
Run Code Online (Sandbox Code Playgroud)

如果我像上面那样设置,它工作正常。