Mid*_*yan 3 navigation google-maps marker ios swift
我在谷歌地图上有一个汽车图标,必须定期移动。位置坐标将从服务器获取,我已经通过执行下面的代码设法更改了标记的位置,但没有得到平滑的移动
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
Run Code Online (Sandbox Code Playgroud)
这里 driverdetails 包含所有必需的数据。只是想知道我可以使用任何动画函数来实现此目的吗?
您可以使用 animate(to: GMSCameraPosition) 通过动画更新地图位置,示例如下所示:-
func updateMapLocation(lattitude:CLLocationDegrees,longitude:CLLocationDegrees){
let camera = GMSCameraPosition.camera(withLatitude: lattitude, longitude: longitude, zoom: 16)
mapView?.camera = camera
mapView?.animate(to: camera)
}
Run Code Online (Sandbox Code Playgroud)
并像这样调用方法
updateMapLocation(lattitude:-33.8683,longitude:151.2086)
Run Code Online (Sandbox Code Playgroud)
编辑
对于标记位置更新,您可以使用单个标记并使用此代码更新其位置
CATransaction.begin()
CATransaction.setAnimationDuration(2.0)
marker.position = coordindates // CLLocationCoordinate2D coordinate
CATransaction.commit()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7419 次 |
| 最近记录: |