Last active
December 17, 2015 14:59
-
-
Save frijole/5628044 to your computer and use it in GitHub Desktop.
find the heading between two geographic coordinates based on http://stackoverflow.com/questions/3809337/calculating-bearing-between-two-cllocationcoordinate2ds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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