Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55f4c220 authored by Ludovic Barman's avatar Ludovic Barman Committed by Gerrit Code Review
Browse files

Merge "LocationFudger: Avoid division by zero" into main

parents 4109b479 2bc155de
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -239,6 +239,15 @@ public class LocationFudger {

    // requires latitude since longitudinal distances change with distance from equator.
    private static double metersToDegreesLongitude(double distance, double lat) {
        return distance / APPROXIMATE_METERS_PER_DEGREE_AT_EQUATOR / Math.cos(Math.toRadians(lat));
        // Needed to convert from longitude distance to longitude degree.
        // X meters near the poles is more degrees than at the equator.
        double cosLat = Math.cos(Math.toRadians(lat));
        // If we are right on top of the pole, the degree is always 0.
        // We return a very small value instead to avoid divide by zero errors
        // later on.
        if (cosLat == 0.0) {
            return 0.0001;
        }
        return distance / APPROXIMATE_METERS_PER_DEGREE_AT_EQUATOR / cosLat;
    }
}