distance2point function

Future<double> distance2point(
  1. GeoPoint p1,
  2. GeoPoint p2
)

calculate approximately distance between two geographique point using haversine formula fore more detail @link: https://www.movable-type.co.uk/scripts/latlong.html return value in metres p1 : (GeoPoint) first point in road p2 : (GeoPoint) last point in road

Implementation

Future<double> distance2point(GeoPoint p1, GeoPoint p2) async {
  final phi1 = p1.latitude * math.pi / 180; // φ, λ in radians
  final phi2 = p2.latitude * math.pi / 180;
  final deltaPhi = (p2.latitude - p1.latitude) * math.pi / 180;
  final deltaLambda = (p2.longitude - p1.longitude) * math.pi / 180;

  final double a =
      sqrtSin(deltaPhi / 2) + sqrtCos2(phi1, phi2) * sqrtSin(deltaLambda / 2);

  final double c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a));

  return earthRadius * c; //metres
}