distance2point function
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
}