I coded a prototype how we could record fewer GPS positions in Mobile Trail Explorer and therefore save some memory but still have the same level of detail of the trail. Video might explain it best. Unoptimized recording is on the left and optimized trail is on the right.
The algorithm simply checks if the current direction have changed since last recorded position. If direction isn’t changed over the tolerance value then we can replace the last position with current position. Otherwise we only append the new position to the trail.
-
public boolean canRemovePreviousPosition(
-
Vector<GpsPosition> positions,
-
GpsPosition pos1) {
-
-
if(positions.size()<2) {
-
return false;
-
}
-
-
GpsPosition pos2 = positions.elementAt(
-
positions.size()-2 );
-
GpsPosition pos3 = positions.elementAt(
-
positions.size()-1 );
-
-
// Calculate last angle of trail
-
double latDelta = pos2.lat – pos3.lat;
-
double lonDelta = pos2.lon – pos3.lon;
-
-
// Calculate current angle
-
double latDelta2 = pos3.lat – pos1.lat;
-
double lonDelta2 = pos3.lon – pos1.lon;
-
double currentAngle =
-
-
// Get absolute value of direction change
-
double angleDelta =
-
-
// Check the tolerance (0.105 radians = 6 degrees)
-
if(angleDelta>0.105) {
-
return false;
-
} else {
-
return true;
-
}
-
}