Visitar URL original
Adds a small fix that keeps VincentyGeodesy#moveInDirection() from re… · mscode/geohash-java@e72e34c · GitHub
Skip to content

Commit e72e34c

Browse files
committed
Adds a small fix that keeps VincentyGeodesy#moveInDirection() from returning too large values, when moving great distances
1 parent d1f443e commit e72e34c

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎README‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ Current development involves getting the following things to run:
3737
Last important changes
3838
----------------------
3939

40+
Version 1.0.6
41+
-------------
42+
43+
- Added a small fix that keeps VincentyGeodesy#moveInDirection() from returning wrong values when moving large distances. [submitted by André Kischkel]
44+
4045
Version 1.0.5
4146
-------------
4247

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>ch.hsr</groupId>
55
<artifactId>ch.hsr.geohash</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.0.5</version>
7+
<version>1.0.6</version>
88
<name>geohash-java</name>
99
<dependencies>
1010
<dependency>

‎src/main/java/ch/hsr/geohash/util/VincentyGeodesy.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ public static WGS84Point moveInDirection(WGS84Point point, double bearingInDegre
7272
double L = lambda - (1 - C) * f * sinAlpha
7373
* (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
7474

75-
return new WGS84Point(lat2 / degToRad, point.getLongitude() + L / degToRad);
75+
double newLat = lat2 / degToRad;
76+
double newLon = point.getLongitude() + L / degToRad;
77+
78+
newLon = (newLon > 180.0 ? 360.0 - newLon : newLon);
79+
newLon = (newLon < -180.0 ? 360.0 + newLon : newLon);
80+
81+
return new WGS84Point(newLat, newLon);
7682
}
7783

7884
public static double distanceInMeters(WGS84Point foo, WGS84Point bar) {

0 commit comments

Comments
 (0)