【发布时间】:2020-02-18 16:53:00
【问题描述】:
我正在调用方向 API 来绘制路线并尝试在用户移动位置时移动当前位置标记图标,但我在实现时面临以下问题。
- 移动图标时,图标好像倾斜了。
- 它不显示路线上的实际用户位置,图标看起来像是在路线的一侧行驶。
- 我在谷歌地图上的位置图标(蓝色图标)不断改变其位置。
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
let direction = newHeading.trueHeading
lastDriverAngleFromNorth = direction
self.sourceMarker?.rotation = (lastDriverAngleFromNorth - mapBearing) - bearingValue
DispatchQueue.main.async {
CATransaction.begin()
CATransaction.setValue(2, forKey: kCATransactionAnimationDuration)
self.gmsmapView?.animate(toBearing: newHeading.magneticHeading)
CATransaction.commit()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let lastLocation = locations.last {
self.currentLocation = lastLocation
let zoom = self.gmsmapView?.camera.zoom ?? 20.0
zoomLevel = zoom
let destination = CLLocation.init(latitude: viewModel.marker.location[0], longitude: viewModel.marker.location[1])
let bearing = getBearingBetweenTwoPoints(point1: lastLocation.coordinate, point2: destination.coordinate)
self.cameraMoveToLocation(toLocation: lastLocation, zoom:zoom, bearing: bearing)
}
}
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
mapBearing = position.bearing
if let coordinate = self.currentLocation?.coordinate{
self.rerouteCalculation(currentLocation:coordinate)
}
self.sourceMarker?.rotation = (lastDriverAngleFromNorth - mapBearing) - bearingValue
}
func cameraMoveToLocation(toLocation: CLLocation, zoom : Float, bearing : Double) {
self.gmsmapView?.animate(toLocation: toLocation.coordinate)
self.sourceMarker?.position = toLocation.coordinate
}
谁能帮帮我,我被困在这里了。
【问题讨论】:
-
你有没有尝试到外面走走,看清楚天空?这听起来像是 GPS 精度问题。
-
位置标记周围的透明蓝色圆圈是当前 GPS 精度误差。你的位置标记在这个区域跳来跳去是正常的。
-
是的,我试过了,但我主要关心的是如何在路线上顺畅地导航车辆图标,包括所有转弯和地图方位
标签: ios swift google-maps google-directions-api