Skip to content

Instantly share code, notes, and snippets.

@frijole
Last active December 17, 2015 14:59
Show Gist options
  • Save frijole/5628044 to your computer and use it in GitHub Desktop.
Save frijole/5628044 to your computer and use it in GitHub Desktop.
// from: current location
float fLat = (currentLocation.coordinate.latitude / 180.0) * M_PI;
float fLng = (currentLocation.coordinate.longitude / 180.0) * M_PI;
// to: waypoint location
float tLat = (waypoint.locationLat / 180.0) * M_PI;
float tLng = (waypoint.locationLon / 180.0) * M_PI;
// calculate it!
float locationHeading = atan2(sin(tLng-fLng)*cos(tLat), cos(fLat)*sin(tLat)-sin(fLat)*cos(tLat)*cos(tLng-fLng));
// print it
NSLog(@"Heading from newLocation to waypoint: %f",locationHeading*180/M_PI);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment