0
我想从地球的任何地方将图像旋转到特定的方向,例如箭头标记到埃菲尔铁塔。我写了一个作为指南针的程序。它表示东西南北方向。如何更新我的代码以找到埃菲尔铁塔(或任何其他固定的地方)的方向。这是代码。如何快速将图像旋转到特定的经纬度?
class ViewController: UIViewController,CLLocationManagerDelegate {
var location: CLLocation!
var imgArrow: UIImageView!
var locationManager: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
imgArrow = UIImageView(image: UIImage(named: "arrow.png"))
self.view.addSubview(imgArrow)
if(!CLLocationManager.locationServicesEnabled()){
return
}
locationManager = CLLocationManager()
locationManager.delegate = self
if(CLLocationManager.headingAvailable()){
locationManager.startUpdatingHeading()
}
}
override func viewDidAppear(animated: Bool) {
imgArrow.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds))
}
func locationManagerShouldDisplayHeadingCalibration(manager: CLLocationManager) -> Bool {
return true
}
func locationManager(manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
let heading:CGFloat = CGFloat(-M_PI * (newHeading.magneticHeading + 90)/180.0)
imgArrow.transform = CGAffineTransformMakeRotation(heading)
print(heading)
}
}
[检查这个问题(http://stackoverflow.com/questions/7173925/how-to-rotate-a-direction-arrow-to-特别是定位) – Elena