Created
July 7, 2014 15:40
-
-
Save mikekavouras/d8651edefcc7de9ba7e6 to your computer and use it in GitHub Desktop.
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
| static double toRadians(double degrees) { return degrees / 180.0 * M_PI; }; | |
| static double toDegrees(double radians) { return radians * 180.0 / M_PI; }; | |
| @implementation NOTagDirectionManager | |
| + (double)directionInDegreesBetweenLocation:(CLLocationCoordinate2D)locationOne | |
| andLocation:(CLLocationCoordinate2D)locationTwo | |
| { | |
| double lat1 = toRadians(locationOne.latitude); | |
| double lng1 = toRadians(locationOne.longitude); | |
| double lat2 = toRadians(locationTwo.latitude); | |
| double lng2 = toRadians(locationTwo.longitude); | |
| double dLon = toRadians(lng2 - lng1); | |
| double dPhi = log(tan(toRadians(lat2) / 2 + M_PI / 4 ) / tan(toRadians(lat1) / 2 + M_PI / 4 )); | |
| if (fabs(dLon) > M_PI) { | |
| dLon = dLon > 0 ? -(2 * M_PI - dLon) : (2 * M_PI + dLon); | |
| } | |
| return toDegrees(atan2(dLon, dPhi)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment