distanceBetween method
Calculates the distance between the supplied coordinates in meters.
The distance between the coordinates is calculated using the Haversine
formula (see https://en.wikipedia.org/wiki/Haversine_formula). The
supplied coordinates startLatitude
, startLongitude
, endLatitude
and
endLongitude
should be supplied in degrees.
Implementation
double distanceBetween(
double startLatitude,
double startLongitude,
double endLatitude,
double endLongitude,
) {
var earthRadius = 6378137.0;
var dLat = _toRadians(endLatitude - startLatitude);
var dLon = _toRadians(endLongitude - startLongitude);
var a = pow(sin(dLat / 2), 2) +
pow(sin(dLon / 2), 2) *
cos(_toRadians(startLatitude)) *
cos(_toRadians(endLatitude));
var c = 2 * asin(sqrt(a));
return earthRadius * c;
}