getRhumbLineDistance method
Returns the rhumb line distance from the current location to the GeoLocation passed in.
@param location the destination location @return the distance in Meters
Implementation
double getRhumbLineDistance(GeoLocation location) {
double earthRadius = 6378137; // Earth's radius in meters (WGS-84)
double dLat = radians(location.getLatitude()) - radians(getLatitude());
double dLon =
(radians(location.getLongitude()) - radians(getLongitude())).abs();
double dPhi = log(tan(radians(location.getLatitude()) / 2 + pi / 4) /
tan(radians(getLatitude()) / 2 + pi / 4));
double q = dLat / dPhi;
if (!(q.abs() <= double.maxFinite)) {
q = cos(radians(getLatitude()));
}
// if dLon over 180° take shorter rhumb across 180° meridian:
if (dLon > pi) {
dLon = 2 * pi - dLon;
}
double d = sqrt(dLat * dLat + q * q * dLon * dLon);
return d * earthRadius;
}