diff --git a/library/src/com/google/maps/android/SphericalUtil.java b/library/src/com/google/maps/android/SphericalUtil.java index d9ecd4c55..429749f82 100644 --- a/library/src/com/google/maps/android/SphericalUtil.java +++ b/library/src/com/google/maps/android/SphericalUtil.java @@ -28,8 +28,9 @@ private SphericalUtil() {} /** * The earth's radius, in meters. + * Mean radius as defined by IUGG. */ - static final double EARTH_RADIUS = 6378137; + static final double EARTH_RADIUS = 6371009; /** * Returns the heading from one LatLng to another LatLng. Headings are @@ -93,7 +94,8 @@ public static LatLng computeOffsetOrigin(LatLng to, double distance, double head // There are two solutions for b. b = n2 * n4 +/- sqrt(), one solution results // in the latitude outside the [-90, 90] range. We first try one solution and // back off to the other if we are outside that range. - double discriminant = n2 * n2 * n1 * n1 + n1 * n1 * n1 * n1 - n1 * n1 * n4 * n4; + double n12 = n1 * n1; + double discriminant = n2 * n2 * n12 + n12 * n12 - n12 * n4 * n4; if (discriminant < 0) { // No real solution which would make sense in LatLng-space. return null; diff --git a/library/tests/src/com/google/maps/android/SphericalUtilTest.java b/library/tests/src/com/google/maps/android/SphericalUtilTest.java index 5bb65113d..515d20962 100644 --- a/library/tests/src/com/google/maps/android/SphericalUtilTest.java +++ b/library/tests/src/com/google/maps/android/SphericalUtilTest.java @@ -204,9 +204,8 @@ public void testComputeOffsetAndBackToOrigin() { start = SphericalUtil.computeOffsetOrigin(new LatLng(90, 0), Math.PI * EARTH_RADIUS / 4, 0); expectLatLngApproxEquals( - new LatLng(90, 0), - SphericalUtil.computeOffset(start, Math.PI * EARTH_RADIUS / 4, 0)); - + new LatLng(90, 0), + SphericalUtil.computeOffset(start, Math.PI * EARTH_RADIUS / 4, 0)); } public void testInterpolate() {