2017-07-24 60 views
0

我正在使用iOS中的Google地圖。我想動畫我的相機,以顯示所有需要的經緯度。我將這些位置存儲在數組中(作爲CLLocationCoordinate2D實例)並使用GMSCoordinateBounds類來添加這些位置。這是我的代碼:(iOS Swift)谷歌地圖animateWithCameraUpdate無法正常工作

 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) 

firstLocation和lastLocation具有正確的值,但相機不具有動畫效果。我錯過了什麼嗎?

回答

1

非常愚蠢的錯誤。包括座標函數返回GMSCoordinateBounds對象。我不得不重新設置它自己的工作是這樣的:

bounds = bounds.includingCoordinate(firstLocation) 

bounds = bounds.includingCoordinate(lastLocation) 

如果我像上面設置,它工作正常。

相關問題