aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/maps/PositionHistory.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/maps/PositionHistory.java')
-rw-r--r--main/src/cgeo/geocaching/maps/PositionHistory.java63
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