i在Google地图中有一个汽车图标,必须定期移动。位置坐标将从服务器获取,我已经通过执行以下代码设法更改了标记的位置,但是didint的移动很平滑
$ git diff feature/C161920-5075-xtp-implementation-of-new-fidessa develop
此处driverdetails包含所有必需的数据。只想知道我可以使用任何动画功能来实现这一目标?
答案 0 :(得分:0)
您可以使用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)
}
并调用这样的方法
updateMapLocation(lattitude:-33.8683,longitude:151.2086)
修改
要更新标记位置,您可以使用单个标记并使用此代码更新其位置
CATransaction.begin()
CATransaction.setAnimationDuration(2.0)
marker.position = coordindates // CLLocationCoordinate2D coordinate
CATransaction.commit()
答案 1 :(得分:0)
请不要使用GMSCameraPosition作为地图中的移动图钉
您可以使用mapView.animate(toLocation:YOUR_COORDINATES)方法在地图中平稳移动图钉
self.mapView.animate(toLocation: CLLocationCoordinate2D(latitude: YOUR_LATITUDE, longitude: YOUR_LONGITUDE))
self.marker.position = coordinate
self.marker.map = self.mapView
希望这会有所帮助!
答案 2 :(得分:0)
尝试一下...
将GMSMapViewDelegate添加到您的班级
self.mapView.delegate = self //呼叫委托
//MARK - MapView delegates
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
self.marker.map = mapView;
self.marker.position = position.target //Your target position
self.mapView.selectedMarker = self.marker //Your marker
DispatchQueue.main.async {
self.marker.snippet = "Getting address... " //Your snippet title
}
}
func mapView(_ mapView:GMSMapView, idleAt position:GMSCameraPosition) {
//Get address with village names and street names
self.getAddressForLatLng(latitude: "\(position.target.latitude)", longitude: "\(position.target.longitude)", zoomLevel: position.zoom)
}