distance method

  1. @override
double distance(
  1. GeoLatLng p1,
  2. GeoLatLng p2
)
override

Calculates distance with Haversine algorithm.

Accuracy can be out by 0.3% More on Wikipedia

Implementation

@override
double distance(final GeoLatLng p1, final GeoLatLng p2) {
  final sinDLat = math.sin((p2.latitudeInRad - p1.latitudeInRad) / 2);
  final sinDLng = math.sin((p2.longitudeInRad - p1.longitudeInRad) / 2);

  // Sides
  final a = sinDLat * sinDLat +
      sinDLng *
          sinDLng *
          math.cos(p1.latitudeInRad) *
          math.cos(p2.latitudeInRad);
  final c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a));

  return EQUATOR_RADIUS * c;
}