I want to calculate the average speed from two point objects. A point object contains a timestamp, Longitude
, Latitude
, and elevation
.
I know that I need to compute the amount of time that has passed between measurements for the first and last points on the track. I was hoping to use the ChronoUnit type for this — specifically, the between method, which I believe can be called on ChronoUnit.SECONDS to measure time intervals in units of seconds.
What I have so far (basically a stub so the UnitTests run):
// Average speed method
public double averageSpeed() {
double avgSpeed = 0;
if (track.size () < 4) {
throw new GPSException ("Not enough points to compute");
} else {
return avgSpeed;
}
}
Points are read from a .csv file, an example of which can be seen here:
Time,Longitude,Latitude,Elevation
2016-02-17T09:34:53Z,-1.536369,53.796796,35.0
2016-02-17T09:35:14Z,-1.536506,53.796819,35.1
2016-02-17T09:35:21Z,-1.536657,53.796798,35.2
2016-02-17T09:35:28Z,-1.536817,53.796783,35.3
2016-02-17T09:35:31Z,-1.536892,53.796711,35.4
2016-02-17T09:35:34Z,-1.536967,53.796623,35.5
My question is I want to know how to calculate and return averageSpeed()
using the ChronoUnit type for this — specifically, the between
method to measure time intervals in units of seconds.