I'm making an app for tracking the driven routes via GPS, for the database I used SQLite. When the current position gets changed, the data (latitude, longitude, date) will be saved into the database, so I have a list of many coordinates+dates in my database.
Now, I want to calculate the distance for the whole route. I know the start and end position and the intermediate positions. I also know how to calculate a distance between two positions. I do NOT know how to calculate the distance for all segments. Can someone help me?
This is how I calculate the distance between two positions:
private double calculateDistance(double fromLong, double fromLat,double toLong, double toLat) {
double d2r = Math.PI / 180;
double dLong = (toLong - fromLong) * d2r;
double dLat = (toLat - fromLat) * d2r;
double a = Math.pow(Math.sin(dLat / 2.0), 2) + Math.cos(fromLat * d2r)
* Math.cos(toLat * d2r) * Math.pow(Math.sin(dLong / 2.0), 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d = 6367000 * c;
return Math.round(d);
}