haversine method

double haversine(
  1. LatLon end
)

Haversine compute distance

Implementation

double haversine(LatLon end)
{
  double dLat = Math.degreesToRadians(end.lat - this.lat);
  double dLon = Math.degreesToRadians(end.lon - this.lon);
  double lat1 = Math.degreesToRadians(this.lat);
  double lat2 = Math.degreesToRadians(end.lat);

  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 RADII_KM * c;
}