I am trying to rotate an image to particular direction from any where of the earth,for example an arrow sign to the eiffel tower. I have written a program which works as a compass. It denotes east west north south directions. How to update my code to find the eiffel tower(or any other fixed place) direction. Here is the code.
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)
}
}