Rotate GMSMarker in direction at which user facing

前端 未结 8 1243
独厮守ぢ
独厮守ぢ 2020-12-28 17:58

I have requirement like on my current location one view will display. It will rotate if device was rotate or location will be change.I research lot but got all the code whic

8条回答
  •  梦谈多话
    2020-12-28 18:37

    Try this, it worked for me

    func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading:CLHeading) {
        UIView.animate(withDuration: 0.005) {
           let angle = newHeading.trueHeading.toRadians() // convert from degrees to radians
           self.yourImageHere.transform = CGAffineTransform(rotationAngle: CGFloat(angle)) // rotate the picture
        }
    }
    override func viewDidLoad() {
       super.viewDidLoad()
       locationManager.startUpdatingHeading()
    }
    

提交回复
热议问题