diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-08-18 11:58:06 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-08-18 11:58:06 +0200 |
| commit | 8938ab7801b4ba7ef231a85ef159cc4493c72c02 (patch) | |
| tree | 2426cc606d467f10493605c867da83599d3c8045 /main/src/cgeo/geocaching/maps/PositionHistory.java | |
| parent | c342b278b84b59165b04419515c16bff944a44e2 (diff) | |
| download | cgeo-8938ab7801b4ba7ef231a85ef159cc4493c72c02.zip cgeo-8938ab7801b4ba7ef231a85ef159cc4493c72c02.tar.gz cgeo-8938ab7801b4ba7ef231a85ef159cc4493c72c02.tar.bz2 | |
fix #3122: Trail jumps to 0° and back.
Diffstat (limited to 'main/src/cgeo/geocaching/maps/PositionHistory.java')
| -rw-r--r-- | main/src/cgeo/geocaching/maps/PositionHistory.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/maps/PositionHistory.java b/main/src/cgeo/geocaching/maps/PositionHistory.java new file mode 100644 index 0000000..9b090fc --- /dev/null +++ b/main/src/cgeo/geocaching/maps/PositionHistory.java @@ -0,0 +1,63 @@ +package cgeo.geocaching.maps; + +import android.location.Location; + +import java.util.ArrayList; + +/** + * Map trail history + */ +public class PositionHistory { + + /** + * minimum distance between two recorded points of the trail + */ + private static final double MINIMUM_DISTANCE_METERS = 10.0; + + /** + * maximum number of positions to remember + */ + private static final int MAX_POSITIONS = 700; + + private ArrayList<Location> history = new ArrayList<Location>(); + + /** + * Adds the current position to the trail history to be able to show the trail on the map. + */ + void rememberTrailPosition(Location coordinates) { + if (coordinates.getAccuracy() >= 50f) { + return; + } + if (coordinates.getLatitude() == 0.0 && coordinates.getLatitude() == 0.0) { + return; + } + if (history.isEmpty()) { + history.add(coordinates); + return; + } + + Location historyRecent = history.get(history.size() - 1); + if (historyRecent.distanceTo(coordinates) <= MINIMUM_DISTANCE_METERS) { + return; + } + + history.add(coordinates); + + // avoid running out of memory + final int itemsToRemove = getHistory().size() - MAX_POSITIONS; + if (itemsToRemove > 0) { + for (int i = 0; i < itemsToRemove; i++) { + getHistory().remove(0); + } + } + } + + public ArrayList<Location> getHistory() { + return history; + } + + public void setHistory(ArrayList<Location> history) { + this.history = history; + } + +}
\ No newline at end of file |
