Вы можете попробовать вот так
extension FloatingPoint {
var degreesToRadians: Self { return self * .pi / 180 }
var radiansToDegrees: Self { return self * 180 / .pi }
}
В ViewController
func getHeadingForDirection(fromCoordinate fromLoc: CLLocationCoordinate2D, toCoordinate toLoc: CLLocationCoordinate2D) -> Float {
let fLat: Float = Float((self.mapView.camera.target.latitude).degreesToRadians)
let fLng: Float = Float((self.mapView.camera.target.longitude).degreesToRadians)
let tLat: Float = Float((fromLoc.latitude).degreesToRadians)
let tLng: Float = Float((fromLoc.longitude).degreesToRadians)
let degree: Float = (atan2(sin(tLng - fLng) * cos(tLat), cos(fLat) * sin(tLat) - sin(fLat) * cos(tLat) * cos(tLng - fLng))).radiansToDegrees
if degree >= 0 {
return degree
} else {
return 360 + degree
}
}
В mapView (_ mapView: GMSMapView, idleAt position: GMSCameraPosition)
self.mapView.animate(toBearing: CLLocationDirection((self.getHeadingForDirection(fromCoordinate: self.pickUpMarker.position, toCoordinate: self.dropOffMarker.position) + 100) ))