Skip to content

Instantly share code, notes, and snippets.

@mikekavouras
Created July 7, 2014 15:40
Show Gist options
  • Select an option

  • Save mikekavouras/d8651edefcc7de9ba7e6 to your computer and use it in GitHub Desktop.

Select an option

Save mikekavouras/d8651edefcc7de9ba7e6 to your computer and use it in GitHub Desktop.
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