Skip to content

Instantly share code, notes, and snippets.

@cordellcp3
Created November 7, 2010 10:12
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 cordellcp3/61dc8a65f9fc8fb662e3 to your computer and use it in GitHub Desktop.
Save cordellcp3/61dc8a65f9fc8fb662e3 to your computer and use it in GitHub Desktop.
public Double CalcDistanceOfTwoGpsCoordinates(Double latitudeA, Double longitudeA, Double latitudeB, Double longitudeB)
{
var pk = 180 / Math.PI;
var a1 = latitudeA / pk;
var a2 = longitudeA / pk;
var b1 = latitudeB / pk;
var b2 = longitudeB/ pk;
var t1 = Math.Cos(a1) * Math.Cos(a2) * Math.Cos(b1) * Math.Cos(b2);
var t2 = Math.Cos(a1) * Math.Sin(a2) * Math.Cos(b1) * Math.Sin(b2);
var t3 = Math.Sin(a1) * Math.Sin(b1);
var tt = Math.Acos(t1 + t2 + t3);
return 6366 * tt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment