Today I want to share with you with two functions related with GPS. The first of them calculates the distance between two points. The distance is given in meters.

```/// <summary>
/// Calculates the distance between two points.
/// </summary>
/// <param name="firstCoordinate">The first coordinate.</param>
/// <param name="secondCoordinate">The second coordinate.</param>
/// <returns>Distance between points in meters</returns>
private static double CalculateDistance(GeoCoordinate firstCoordinate, GeoCoordinate secondCoordinate)
{
double R = 6371.0; // km

double dLat = lat2 - lat1;
double dLon = lon2 - lon1;

double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Sin(dLon / 2) * Math.Sin(dLon / 2) * Math.Cos(lat1) * Math.Cos(lat2);
double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
return R * c * 1000;
}```

While the second function is used to find the coordinates of a point, which is located in the middle of the two given points.

```/// <summary>
/// Calculates the middle point coordinate.
/// </summary>
/// <param name="firstCoordinate">The first coordinate.</param>
/// <param name="secondCoordinate">The second coordinate.</param>
/// <returns>Middle point coordinate</returns>
private GeoCoordinate CalculateMidPoint(GeoCoordinate firstCoordinate, GeoCoordinate secondCoordinate)
{

double deltaLong = lon2 - lon1;

double Bx = Math.Cos(lat2) * Math.Cos(deltaLong);
double By = Math.Cos(lat2) * Math.Sin(deltaLong);
double lat3 = RadToDeg(Math.Atan2(Math.Sin(lat1) + Math.Sin(lat2), Math.Sqrt((Math.Cos(lat1) + Bx) * (Math.Cos(lat1) + Bx) + By * By)));
double lon3 = RadToDeg(lon1 + Math.Atan2(By, Math.Cos(lat1) + Bx));

return new GeoCoordinate(lat3, lon3);
}```

Both functions use two auxiliary methods, which convert degrees to radians and vice versa.

```/// <summary>
/// </summary>
/// <returns>The degrees.</returns>
{
return radians * (180 / Math.PI);
}

/// <summary>