Skip to content

Instantly share code, notes, and snippets.

@kucheruk
Created April 17, 2012 17:50
Show Gist options
  • Save kucheruk/2407778 to your computer and use it in GitHub Desktop.
Save kucheruk/2407778 to your computer and use it in GitHub Desktop.
haversine formula (miles/meters)
double miles = 3956d*2d*Math.Asin
(Math.Sqrt
(Math.Pow(Math.Sin
((orig_lat - dest_lat)*Math.PI/180d/2d),
2
)
+ Math.Cos(orig_lat*Math.PI/180d)
*Math.Cos(dest_lat*Math.PI/180d)
*Math.Pow(Math.Sin((orig_lon - dest_lon)*Math.PI/180d/2d), 2
)
)
);
var distanceInMeters = miles*1609.344;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment