Last active
July 15, 2021 14:18
-
-
Save yanandrey/bdd952990307ea5ed82b1df41f7b9f33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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