calculateDistance static method Null safety

double calculateDistance(
  1. double latStart,
  2. double lonStart,
  3. double latEnd,
  4. double lonEnd
)

Implementation

static double calculateDistance(
    double latStart, double lonStart, double latEnd, double lonEnd) {
  var R = 3958.8; // Radius of the earth in miles
  var dLat = _deg2rad(latEnd - latStart); // deg2rad below
  var dLon = _deg2rad(lonEnd - lonStart);
  var a = sin(dLat / 2) * sin(dLat / 2) +
      cos(_deg2rad(latStart)) *
          cos(_deg2rad(latEnd)) *
          sin(dLon / 2) *
          sin(dLon / 2);
  var c = 2 * atan2(sqrt(a), sqrt(1 - a));
  var d = R * c; // Distance in miles
  return d;
}