Skip to content

Instantly share code, notes, and snippets.

@mstefanko
Created March 28, 2011 13:27
Show Gist options
  • Save mstefanko/890446 to your computer and use it in GitHub Desktop.
Save mstefanko/890446 to your computer and use it in GitHub Desktop.
Distence calculation between two GPS points
private double gps2m(float lat_a, float lng_a, float lat_b, float lng_b) {
float pk = (float) (180/3.14169);
float a1 = lat_a / pk;
float a2 = lng_a / pk;
float b1 = lat_b / pk;
float b2 = lng_b / pk;
float t1 = FloatMath.cos(a1)*FloatMath.cos(a2)*FloatMath.cos(b1)*FloatMath.cos(b2);
float t2 = FloatMath.cos(a1)*FloatMath.sin(a2)*FloatMath.cos(b1)*FloatMath.sin(b2);
float t3 = FloatMath.sin(a1)*FloatMath.sin(b1);
double tt = Math.acos(t1 + t2 + t3);
return 6366000*tt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment