Skip to content

Instantly share code, notes, and snippets.

@yanandrey
Last active July 15, 2021 14:18
Show Gist options
  • Save yanandrey/bdd952990307ea5ed82b1df41f7b9f33 to your computer and use it in GitHub Desktop.
Save yanandrey/bdd952990307ea5ed82b1df41f7b9f33 to your computer and use it in GitHub Desktop.
public int GetDistanceStraightLine(double latOrg, double lngOrg, double latDest, double lngDest)
{
const double radius = 6378.137;
var dLat = latDest * Math.PI / 180 - latOrg * Math.PI / 180;
var dLng = lngDest * Math.PI / 180 - lngOrg * Math.PI / 180;
var a = Math.Sin(dLat / 2) *
Math.Sin(dLat / 2) +
Math.Cos(latOrg * Math.PI / 180) *
Math.Cos(latDest * Math.PI / 180) *
Math.Sin(dLng / 2) *
Math.Sin(dLng / 2);
var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
var d = radius * c * 1000;
return (int) d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment