Skip to content

Instantly share code, notes, and snippets.

@aaryadev
Created February 28, 2015 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaryadev/ca8da82c925539fae9df to your computer and use it in GitHub Desktop.
Save aaryadev/ca8da82c925539fae9df to your computer and use it in GitHub Desktop.
distance between 2 gps location
static double EARTH_RADIUS = 6378100;// radius of earth in meters
public static double gpsdistance (double lat1, double long1, double lat2, double long2)
{
//in meters :D
double degToRad= Math.PI / 180.0;
double phi1 = lat1 * degToRad;
double phi2 = lat2 * degToRad;
double lam1 = long1 * degToRad;
double lam2 = long2 * degToRad;
return EARTH_RADIUS * Math.acos( Math.sin(phi1) * Math.sin(phi2) + Math.cos(phi1) * Math.cos(phi2) * Math.cos(lam2 - lam1) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment