calculate distance between two coordinates c# code example
Example 1: distance between two points latitude longitude c#
float DeltaFi = (float)ConvertToRadians(lat2 - lat1);
float DeltaLambda = (float)ConvertToRadians(lon2 - lon1);
float a = Mathf.Sin(DeltaFi / 2) * Mathf.Sin(DeltaFi / 2) + Mathf.Cos(fi1) * Mathf.Cos(fi2) * Mathf.Sin(DeltaLambda / 2) * Mathf.Sin(DeltaLambda / 2);
float c = 2 * Mathf.Atan2(Mathf.Sqrt(a), Mathf.Sqrt(1 - a));
float distance = earthD * c;
Example 2: Input the coördinates and calculate the distance between them c#
static void Main() {
double d, x1, x2, y1, y2;
Console.Write("Enter coordinates for point A: ");
x1 = Double.Parse(Console.ReadLine());
y1 = Double.Parse(Console.ReadLine());
Console.Write("Enter coordinates for point B: ");
x2 = Double.Parse(Console.ReadLine());
y2 = Double.Parse(Console.ReadLine());
d = Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
Console.Write("Distance between points: " + d);
Console.ReadKey();
}
Example 3: formula calculating distance coordinates latitude longitude c#
lattitudelongitudecalculation