我在谷歌地图上有一个汽车图标,必须定期移动。位置坐标将从服务器获取,我已经通过执行下面的代码设法更改了标记的位置,但没有顺利移动
let camera = GMSCameraPosition.camera(withLatitude: (((self.driverArrival.value(forKey: "latitude")) as AnyObject).doubleValue)!,
longitude: (((self.driverArrival.value(forKey: "longitude")) as AnyObject).doubleValue)!, zoom: 15)
let position = CLLocationCoordinate2DMake((((self.driverArrival.value(forKey: "latitude")) as AnyObject).doubleValue)!, (((self.driverArrival.value(forKey: "longitude")) as AnyObject).doubleValue)!)
driverMarker.position = position
driverMarker.map = self.mapView
这里的 driverdetails 包含所有需要的数据。只是想知道我可以使用任何动画功能来实现这一点吗?
最佳答案
您可以使用 animate(to: GMSCameraPosition) 通过动画更新 map 位置,示例如下所示:-
func updateMapLocation(lattitude:CLLocationDegrees,longitude:CLLocationDegrees){
let camera = GMSCameraPosition.camera(withLatitude: lattitude, longitude: longitude, zoom: 16)
mapView?.camera = camera
mapView?.animate(to: camera)
}
然后像这样调用方法
updateMapLocation(lattitude:-33.8683,longitude:151.2086)
编辑
对于标记位置更新,您可以使用单个标记并使用此代码更新其位置
CATransaction.begin()
CATransaction.setAnimationDuration(2.0)
marker.position = coordindates // CLLocationCoordinate2D coordinate
CATransaction.commit()
关于ios - 如何在 ios 中将 Google map 标记从一个位置平滑地动画化到另一个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52732467/