Persist elevation received from OpenTracks

This commit is contained in:
Arjan Schrijver
2025-07-26 22:22:00 +02:00
committed by Arjan Schrijver
parent d6cb501e52
commit 95c16c7eb5
@@ -133,6 +133,7 @@ public class OpenTracksContentObserver extends ContentObserver {
public static final String TIME = "time";
public static final String TYPE = "type";
public static final String SPEED = "speed";
public static final String ELEVATION = "elevation";
public static final double PAUSE_LATITUDE = 100.0;
public static final double LAT_LON_FACTOR = 1E6;
public static final String[] PROJECTION_V1 = {
@@ -150,7 +151,8 @@ public class OpenTracksContentObserver extends ContentObserver {
LONGITUDE,
TIME,
TYPE,
SPEED
SPEED,
ELEVATION
};
public void readTrackPointsBySegments(Uri data) {
String[] projection = PROJECTION_V2;
@@ -167,6 +169,7 @@ public class OpenTracksContentObserver extends ContentObserver {
double longitude = cursor.getInt(cursor.getColumnIndexOrThrow(LONGITUDE)) / LAT_LON_FACTOR;
int typeIndex = cursor.getColumnIndex(TYPE);
double speed = cursor.getDouble(cursor.getColumnIndexOrThrow(SPEED));
double elevation = cursor.getDouble(cursor.getColumnIndexOrThrow(ELEVATION));
Date time = Date.from(Instant.ofEpochMilli(cursor.getLong(cursor.getColumnIndexOrThrow(TIME))));
int type = 0;
@@ -179,13 +182,13 @@ public class OpenTracksContentObserver extends ContentObserver {
lastTrackId = trackId;
}
LOG.debug("Trackpoint received from OpenTracks: {}/{} type={} speed={} time={}", latitude, longitude, type, speed, time);
LOG.debug("Trackpoint received from OpenTracks: {}/{} type={} speed={} elev={} time={}", latitude, longitude, type, speed, elevation, time);
ActivityPoint activityPoint = new ActivityPoint();
activityPoint.setTime(time);
activityPoint.setSpeed((float) speed);
if ((latitude != 0 || longitude != 0) && latitude != PAUSE_LATITUDE) {
activityPoint.setLocation(new GPSCoordinate(longitude, latitude));
activityPoint.setLocation(new GPSCoordinate(longitude, latitude, elevation));
} else if (previousActivityPoint != null && previousActivityPoint.getLocation() != null && (type == 3 || latitude == PAUSE_LATITUDE)) {
activityPoint.setLocation(previousActivityPoint.getLocation());
}