From 137d49e23c3963d8e001fbc89e7b600200de171b Mon Sep 17 00:00:00 2001 From: Mihai Preda Date: Thu, 22 Aug 2013 14:49:02 +1000 Subject: [PATCH 1/2] Update Earth radius. --- library/src/com/google/maps/android/SphericalUtil.java | 6 ++++-- .../src/com/google/maps/android/SphericalUtilTest.java | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) 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..a65600205 100644 --- a/library/tests/src/com/google/maps/android/SphericalUtilTest.java +++ b/library/tests/src/com/google/maps/android/SphericalUtilTest.java @@ -203,10 +203,11 @@ public void testComputeOffsetAndBackToOrigin() { // arbitrary. start = SphericalUtil.computeOffsetOrigin(new LatLng(90, 0), Math.PI * EARTH_RADIUS / 4, 0); - expectLatLngApproxEquals( + if (start != null) { + expectLatLngApproxEquals( new LatLng(90, 0), SphericalUtil.computeOffset(start, Math.PI * EARTH_RADIUS / 4, 0)); - + } } public void testInterpolate() { From af3480f79738209320c27bdbb9966f9d60b9a6cf Mon Sep 17 00:00:00 2001 From: Mihai Preda Date: Tue, 27 Aug 2013 18:11:16 +1000 Subject: [PATCH 2/2] Revert null check in testComputeOffsetAndBackToOrigin. --- .../src/com/google/maps/android/SphericalUtilTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/library/tests/src/com/google/maps/android/SphericalUtilTest.java b/library/tests/src/com/google/maps/android/SphericalUtilTest.java index a65600205..515d20962 100644 --- a/library/tests/src/com/google/maps/android/SphericalUtilTest.java +++ b/library/tests/src/com/google/maps/android/SphericalUtilTest.java @@ -203,11 +203,9 @@ public void testComputeOffsetAndBackToOrigin() { // arbitrary. start = SphericalUtil.computeOffsetOrigin(new LatLng(90, 0), Math.PI * EARTH_RADIUS / 4, 0); - if (start != null) { - expectLatLngApproxEquals( - new LatLng(90, 0), - SphericalUtil.computeOffset(start, Math.PI * EARTH_RADIUS / 4, 0)); - } + expectLatLngApproxEquals( + new LatLng(90, 0), + SphericalUtil.computeOffset(start, Math.PI * EARTH_RADIUS / 4, 0)); } public void testInterpolate() {