distanceCoordsSuperFast function Null safety

double distanceCoordsSuperFast(
  1. double latADeg,
  2. double longADeg,
  3. double latBDeg,
  4. double longBDeg
)

Calculates an approximation of the distance in meters between point A at spherical (latitude, longitude) coordinates (latADeg, longADeg) and B at (latBDeg, longBDeg) - all in degrees.

Implementation

double distanceCoordsSuperFast(
    double latADeg, double longADeg, double latBDeg, double longBDeg) {
  final meterPerDegLongA = getMetersPerLongitudeDegAtLatitudeDeg(latADeg);
  final meterPerDegLongB = getMetersPerLongitudeDegAtLatitudeDeg(latBDeg);
  final averageMeterPerLongDeg = (meterPerDegLongA + meterPerDegLongB) / 2;
  final distLongMeter =
      averageMeterPerLongDeg * deltaLongitudeAbs(longADeg, longBDeg);

  var diffLatDeg = deltaLatitudeAbs(latADeg, latBDeg);
  final distLatMeter = metersPerDegreeLatitude * diffLatDeg;

  return sqrt(distLongMeter * distLongMeter + distLatMeter * distLatMeter);
}