-1

I need to make a marker that can rotate automatically like the direction of the phone. Please, can anyone help me to do this? I'm creating like Uber marker, so the marker should be a car. Thank you

This the link of the map that I try to create

Community
  • 1
  • 1

1 Answers1

1

i found the solution by myself..

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {

    let direction = newHeading.magneticHeading
    let radians = -direction / 180.0 * .pi
    let angle = SupportFunc.radiansToDegress(radians: CGFloat(radians))

    DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
        self.mapView.animate(toBearing: CLLocationDirection(-angle))
    }
}
static func radiansToDegress(radians: CGFloat) -> CGFloat {
    return radians * 180 / CGFloat(Double.pi)
}