Skip to content

Instantly share code, notes, and snippets.

@ryanhanwu
Created September 10, 2014 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanhanwu/80fbba02347d9d1853ec to your computer and use it in GitHub Desktop.
Save ryanhanwu/80fbba02347d9d1853ec to your computer and use it in GitHub Desktop.
campass heading
There is no native compass UIView. In order to use the magnetometer, you'll have to use CoreLocation and the following delegate method:
- (void) locationManager:(CLLocationManager *)manager
didUpdateHeading:(CLHeading *)newHeading
to rotate a UIView to point North (bearingView is a UIImageView):
float heading = newHeading.magneticHeading; //in degrees
float headingDegrees = (heading*M_PI/180); //assuming needle points to top of iphone. convert to radians
self.bearingView.transform = CGAffineTransformMakeRotation(headingDegrees);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment