Created
April 9, 2012 04:18
-
-
Save georgel/2341397 to your computer and use it in GitHub Desktop.
Calculate distance between 2 cllocation
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
#define DEG_TO_RAD 0.017453292519943295769236907684886 | |
#define EARTH_RADIUS 6372797.560856 | |
// return distance between two lat/lon points, in meters | |
double DistanceBetweenCoords(double fromLat, double fromLong, double toLat, | |
double toLong) | |
{ | |
double latitudeArc = (fromLat - toLat) * DEG_TO_RAD; | |
double longitudeArc = (fromLong - toLong) * DEG_TO_RAD; | |
double latitudeH = sin(latitudeArc * 0.5); | |
latitudeH *= latitudeH; | |
double lontitudeH = sin(longitudeArc * 0.5); | |
lontitudeH *= lontitudeH; | |
double tmp = cos(fromLat*DEG_TO_RAD) * cos(toLat*DEG_TO_RAD); | |
return 2.0 * asin(sqrt(latitudeH + tmp*lontitudeH)) * EARTH_RADIUS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment