distance method
Haversine formula. Giving great-circle distances between two points on a sphere from their longitudes and latitudes. It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the sides and angles of spherical "triangles".
Based on ref link: https://gist.github.com/jferrao/cb44d09da234698a7feee68ca895f491 startPoint Initial coordinates endPoint Final coordinates @return Distance in kilometers
final istCoordinates = Coordinate(41.28111111, 28.75333333); // The coordinates of Istanbul Airport
final jfkCoordinates = Coordinate(40.63980103, -73.77890015); // The coordinates of New York JFK Airport
final greatCircle = GreatCircle();
final distance = greatCircle.distance(istCoordinates, jfkCoordinates);
Implementation
double distance(Coordinate startPoint, Coordinate endPoint) {
final double lat1 = startPoint.latitude;
final double lat2 = endPoint.latitude;
final double lon1 = startPoint.longitude;
final double lon2 = endPoint.longitude;
final double dLat = (lat2 - lat1).toRadians();
final double dLon = (lon2 - lon1).toRadians();
final double a = pow(sin(dLat / 2), 2) +
pow(sin(dLon / 2), 2) * cos(lat1.toRadians()) * cos(lat2.toRadians());
final double c = 2 * asin(sqrt(a));
return earthRadiusKm * c;
}