Added position update in yacht #story[1047]

This commit is contained in:
Peter Galloway
2017-07-19 19:39:31 +12:00
committed by Peter
parent 67668fe1fc
commit 63d24c001f
2 changed files with 28 additions and 12 deletions
+13
View File
@@ -81,6 +81,19 @@ public class Yacht {
this.position = "-";
}
/**
* @param timeInterval since last update in milliseconds
*/
public void update(Long timeInterval) {
Double secondsElapsed = timeInterval / 1000000.0;
Double metersCovered = velocity * secondsElapsed;
// 111111 meters is approximately 1 degree of lat/long at the equator
lat = lat + (metersCovered * Math.sin(heading * (2 * Math.PI / 360))) / 111111;
lon = lon + (metersCovered * Math.cos(heading * (2 * Math.PI / 360))) / (111111 * Math
.cos(lat * (2 * Math.PI / 360)));
// formula take from https://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters
}
public String getBoatType() {
return boatType;
}