我想通过更改方位角值来旋转 GMap,因此相机围绕中心点旋转(360 度一整圈)。当我们改变方位时,在相机起点和终点会有缓动效果。如何控制/更改它以在更改Bearing
值时使旋转平滑(以 360 度旋转地图,平滑动画)?
所有语言都需要这个,因为不同语言库中的缓动效果似乎不同。例如 Swift、Android、PHP、JS、Node.js、React。
Swift 示例(在线性动画中运行良好):
请注意,最初动画在 iOS 中也确实存在抖动,但是当我们CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear
沿其CATransaction
属性使用时,GMap 动画变成了平滑动画。所以现在如果你看到下面的代码,Bearing
值的变化不会产生生涩的效果(由于 GMap 动画中的缓动效果)。我也在寻找合适的解决Android
方案Web
。
//Move the map around current location, first loop
let timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
CATransaction.begin()
CATransaction.setValue(3.0, forKey: kCATransactionAnimationDuration)
CATransaction.setAnimationTimingFunction(timingFunction)
CATransaction.setCompletionBlock({
//Move the map around current location, second loop
let timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
CATransaction.begin()
CATransaction.setValue(3.0, forKey: kCATransactionAnimationDuration)
CATransaction.setAnimationTimingFunction(timingFunction)
CATransaction.setCompletionBlock({
//Move the map around current location, third loop
let timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
CATransaction.begin()
CATransaction.setValue(3.0, forKey: kCATransactionAnimationDuration)
CATransaction.setAnimationTimingFunction(timingFunction)
CATransaction.setCompletionBlock({
UIView.animate(withDuration: 0.5, animations: {
self.findingYourLocation.alpha = 0.0
})
//TODO: Set nearest branch
// Zoom in one zoom level
let zoomCamera = GMSCameraUpdate.zoomIn()
self.mapView.animate(with: zoomCamera)
// Center the camera on UBL Branch when animation finished
//let nearestBranch = CLLocationCoordinate2D(latitude: 24.850751, longitude: 67.016589)
let nearestBranch = CLLocationCoordinate2D.init(latitude: 24.806849, longitude: 67.038734)
let nearestBranchCam = GMSCameraUpdate.setTarget(nearestBranch)
CATransaction.begin()
let timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
CATransaction.setValue(3.0, forKey: kCATransactionAnimationDuration)
CATransaction.setAnimationTimingFunction(timingFunction)
CATransaction.setCompletionBlock({
self.nextButton.alpha = 1.0
})
self.mapView.animate(with: nearestBranchCam)
self.mapView.animate(toZoom: 15)
self.mapView.animate(toBearing: 0)
self.mapView.animate(toViewingAngle: 0)
CATransaction.commit()
})
self.mapView.animate(toBearing: self.mapView.camera.bearing + 120)
CATransaction.commit()
})
self.mapView.animate(toBearing: self.mapView.camera.bearing + 120)
CATransaction.commit()
})
self.mapView.animate(toBearing: self.mapView.camera.bearing + 120)
CATransaction.commit()
Android示例代码(有问题):
可以在此处找到 Android 示例/示例代码:https ://issuetracker.google.com/issues/71738889
其中还包括一个.apk
文件,一个.mp4
示例应用程序输出的视频。Bearing
这清楚地显示了在 360 度旋转地图时值发生变化时的抖动效果。