title: Point to location using compass
body: <p>I am trying to develop a compass for an appliation which has a set of annotations on a map. I would like to be able to choose an annotation and then have the compass point the user to the chosen location.</p>
  
  <p>I have calculated the degress from the user's location to the location of the annotation and I have the magnetic heading and the true heading of the iPhone. Also I know how to rotate an image.
  But I can't figure out what the next step is.</p>
  
  <p>The degrees between the user's location and the annotation location is calculated like this:</p>
  
  <pre><code>    // get user location
      locationManager = [[CLLocationManager alloc] init];
      locationManager.delegate = self; 
      locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
      locationManager.distanceFilter = kCLDistanceFilterNone; 
      [locationManager startUpdatingLocation];
      [locationManager startUpdatingHeading];
      CLLocation *location = [locationManager location];
      CLLocationCoordinate2D coordinate = [location coordinate];
  
      float x1 = coordinate.latitude;
      float y1 = coordinate.longitude;
      float x2 = [annLatitude floatValue];
      float y2 = [annLongitude floatValue];
  
      float dx = (x2 - x1);
      float dy = (y2 - y1);
  
      if (dx == 0) {
          if (dy &gt; 0) {
              result = 90;
          }
          else {
              result = 270;
          }
      }
      else {
          result = (atan(dy/dx)) * 180 / M_PI;
      }
  
      if (dx &lt; 0) {
          result = result + 180;
      }
  
      if (result &lt; 0) {
          result = result + 360;
      }
  </code></pre>
  
  <p>The true and the magnetic heading is retrieved like this:</p>
  
  <pre><code>- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
      arrow.transform = CGAffineTransformMakeRotation(newHeading.magneticHeading);
  
      // NSLog(@"magnetic heading: %f", newHeading.magneticHeading);
      // NSLog(@"true heading: %f", newHeading.trueHeading);
  }
  </code></pre>
  
  <p>Can anyone tell me what I should do now to make the arrow point to the location - even if the iPhone is rotated?</p>