distanceTo method

double distanceTo(
  1. GpsCoordinates other
)

Calculate Euclidean distance between current coordinates and another set of coordinates.

See https://en.wikipedia.org/wiki/Geographic_coordinate_system#Length_of_a_degree

Implementation

double distanceTo(GpsCoordinates other) {
  // Convert to distance in meters and use Pythagorean theorem
  final latitudeDistance =
      111132.92 -
      559.82 * cos(2 * latitude * pi / 180) +
      1.175 * cos(4 * latitude * pi / 180) -
      0.0023 * cos(6 * latitude * pi / 180);
  final longitudeDistance =
      111412.84 * cos(latitude * pi / 180) -
      93.5 * cos(3 * latitude * pi / 180) +
      0.118 * cos(5 * latitude * pi / 180);

  return sqrt(
    pow((latitude - other.latitude) * latitudeDistance, 2) +
        pow((longitude - other.longitude) * longitudeDistance, 2) +
        pow(altitude - other.altitude, 2),
  );
}