diff options
Diffstat (limited to 'src/org/traccar/helper/DistanceCalculator.java')
-rw-r--r-- | src/org/traccar/helper/DistanceCalculator.java | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/org/traccar/helper/DistanceCalculator.java b/src/org/traccar/helper/DistanceCalculator.java index 072f3d7a8..7ba5044bc 100644 --- a/src/org/traccar/helper/DistanceCalculator.java +++ b/src/org/traccar/helper/DistanceCalculator.java @@ -17,16 +17,16 @@ package org.traccar.helper; public class DistanceCalculator { - private static final double equatorialEarthRadius = 6378.1370D; - private static final double deg2rad = (Math.PI / 180); + private static final double EQUATORIAL_EARTH_RADIUS = 6378.1370; + private static final double DEG_TO_RAD = Math.PI / 180; public static double distance(double lat1, double lon1, double lat2, double lon2) { - double dlong = (lon2 - lon1) * deg2rad; - double dlat = (lat2 - lat1) * deg2rad; + double dlong = (lon2 - lon1) * DEG_TO_RAD; + double dlat = (lat2 - lat1) * DEG_TO_RAD; double a = Math.pow(Math.sin(dlat / 2), 2) + - Math.cos(lat1 * deg2rad) * Math.cos(lat2 * deg2rad) * Math.pow(Math.sin(dlong / 2), 2); + Math.cos(lat1 * DEG_TO_RAD) * Math.cos(lat2 * DEG_TO_RAD) * Math.pow(Math.sin(dlong / 2), 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); - double d = equatorialEarthRadius * c; + double d = EQUATORIAL_EARTH_RADIUS * c; return d * 1000; } |