computeDistanceHaversine function

num computeDistanceHaversine(
  1. LatLng p1,
  2. LatLng p2, {
  3. num radius = earthRadius,
})

Compute distance between 2 points according to Haversine formula.

Implementation

num computeDistanceHaversine(
  LatLng p1,
  LatLng p2, {
  num radius = earthRadius,
}) {
  final sDLat = sin((degToRad(p2.lat) - degToRad(p1.lat)) / 2);
  final sDLng = sin((degToRad(p2.lng) - degToRad(p1.lng)) / 2);
  final a = sDLat * sDLat +
      sDLng * sDLng * cos(degToRad(p1.lat)) * cos(degToRad(p2.lat));
  final c = 2 * atan2(sqrt(a), sqrt(1 - a));
  return radius * c;
}