forked from upstream-mirrors/OpenTracks
Record idle location to support zero speed when idle
This commit is contained in:
@@ -93,6 +93,11 @@ public class TrackRecordingService extends Service {
|
|||||||
public static final double PAUSE_LATITUDE = 100.0;
|
public static final double PAUSE_LATITUDE = 100.0;
|
||||||
public static final double RESUME_LATITUDE = 200.0;
|
public static final double RESUME_LATITUDE = 200.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anything faster than that (in meters per second) will be considered moving.
|
||||||
|
*/
|
||||||
|
public static final double MAX_NO_MOVEMENT_SPEED = 0.224;
|
||||||
|
|
||||||
private static final String TAG = TrackRecordingService.class.getSimpleName();
|
private static final String TAG = TrackRecordingService.class.getSimpleName();
|
||||||
private static final long ONE_SECOND = 1000; // in milliseconds
|
private static final long ONE_SECOND = 1000; // in milliseconds
|
||||||
private static final long ONE_MINUTE = 60 * ONE_SECOND; // in milliseconds
|
private static final long ONE_MINUTE = 60 * ONE_SECOND; // in milliseconds
|
||||||
@@ -127,6 +132,7 @@ public class TrackRecordingService extends Service {
|
|||||||
private SensorManager sensorManager;
|
private SensorManager sensorManager;
|
||||||
private Location lastLocation;
|
private Location lastLocation;
|
||||||
private boolean currentSegmentHasLocation;
|
private boolean currentSegmentHasLocation;
|
||||||
|
private boolean isIdle; // true if idle
|
||||||
|
|
||||||
private ServiceBinder binder = new ServiceBinder(this);
|
private ServiceBinder binder = new ServiceBinder(this);
|
||||||
|
|
||||||
@@ -704,6 +710,7 @@ public class TrackRecordingService extends Service {
|
|||||||
sensorManager = SensorManagerFactory.getSystemSensorManager(this);
|
sensorManager = SensorManagerFactory.getSystemSensorManager(this);
|
||||||
lastLocation = null;
|
lastLocation = null;
|
||||||
currentSegmentHasLocation = false;
|
currentSegmentHasLocation = false;
|
||||||
|
isIdle = false;
|
||||||
|
|
||||||
startGps();
|
startGps();
|
||||||
sendTrackBroadcast(trackStarted ? R.string.track_started_broadcast_action
|
sendTrackBroadcast(trackStarted ? R.string.track_started_broadcast_action
|
||||||
@@ -932,10 +939,9 @@ public class TrackRecordingService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double distanceToLastTrackLocation = location.distanceTo(lastValidTrackPoint);
|
double distanceToLastTrackLocation = location.distanceTo(lastValidTrackPoint);
|
||||||
if (distanceToLastTrackLocation < recordingDistanceInterval && sensorDataSet == null) {
|
if (distanceToLastTrackLocation > maxRecordingDistance) {
|
||||||
Log.d(TAG, "Not recording location due to recording distance interval.");
|
|
||||||
} else if (distanceToLastTrackLocation > maxRecordingDistance) {
|
|
||||||
insertLocation(track, lastLocation, lastValidTrackPoint);
|
insertLocation(track, lastLocation, lastValidTrackPoint);
|
||||||
|
|
||||||
Location pause = new Location(LocationManager.GPS_PROVIDER);
|
Location pause = new Location(LocationManager.GPS_PROVIDER);
|
||||||
pause.setLongitude(0);
|
pause.setLongitude(0);
|
||||||
pause.setLatitude(PAUSE_LATITUDE);
|
pause.setLatitude(PAUSE_LATITUDE);
|
||||||
@@ -943,13 +949,22 @@ public class TrackRecordingService extends Service {
|
|||||||
insertLocation(track, pause, null);
|
insertLocation(track, pause, null);
|
||||||
|
|
||||||
insertLocation(track, location, null);
|
insertLocation(track, location, null);
|
||||||
} else {
|
isIdle = false;
|
||||||
/*
|
} else if (sensorDataSet != null
|
||||||
* (distanceToLastTrackLocation >= minRecordingDistance ||
|
|| distanceToLastTrackLocation >= recordingDistanceInterval) {
|
||||||
* hasSensorData) && distanceToLastTrackLocation <= maxRecordingDistance
|
|
||||||
*/
|
|
||||||
insertLocation(track, lastLocation, lastValidTrackPoint);
|
insertLocation(track, lastLocation, lastValidTrackPoint);
|
||||||
insertLocation(track, location, null);
|
insertLocation(track, location, null);
|
||||||
|
isIdle = false;
|
||||||
|
} else if (!isIdle && location.hasSpeed() && location.getSpeed() < MAX_NO_MOVEMENT_SPEED) {
|
||||||
|
insertLocation(track, lastLocation, lastValidTrackPoint);
|
||||||
|
insertLocation(track, location, null);
|
||||||
|
isIdle = true;
|
||||||
|
} else if (isIdle && location.hasSpeed() && location.getSpeed() >= MAX_NO_MOVEMENT_SPEED) {
|
||||||
|
insertLocation(track, lastLocation, lastValidTrackPoint);
|
||||||
|
insertLocation(track, location, null);
|
||||||
|
isIdle = false;
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Not recording location, idle");
|
||||||
}
|
}
|
||||||
lastLocation = location;
|
lastLocation = location;
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
package com.google.android.apps.mytracks.stats;
|
package com.google.android.apps.mytracks.stats;
|
||||||
|
|
||||||
import static com.google.android.apps.mytracks.Constants.TAG;
|
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||||
|
import static com.google.android.apps.mytracks.services.TrackRecordingService.MAX_NO_MOVEMENT_SPEED;
|
||||||
|
import static com.google.android.apps.mytracks.services.TrackRecordingService.PAUSE_LATITUDE;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.services.TrackRecordingService;
|
|
||||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
@@ -66,11 +67,6 @@ public class TripStatisticsUpdater {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int SPEED_SMOOTHING_FACTOR = 25;
|
static final int SPEED_SMOOTHING_FACTOR = 25;
|
||||||
|
|
||||||
/**
|
|
||||||
* Anything faster than that (in meters per second) will be considered moving.
|
|
||||||
*/
|
|
||||||
private static final double MAX_NO_MOVEMENT_SPEED = 0.224;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ignore any acceleration faster than this. Will ignore any speeds that imply
|
* Ignore any acceleration faster than this. Will ignore any speeds that imply
|
||||||
* acceleration greater than 2g's 2g = 19.6 m/s^2 = 0.0002 m/ms^2 = 0.02
|
* acceleration greater than 2g's 2g = 19.6 m/s^2 = 0.0002 m/ms^2 = 0.02
|
||||||
@@ -142,7 +138,7 @@ public class TripStatisticsUpdater {
|
|||||||
|
|
||||||
if (!LocationUtils.isValidLocation(location)) {
|
if (!LocationUtils.isValidLocation(location)) {
|
||||||
// Either pause or resume marker
|
// Either pause or resume marker
|
||||||
if (location.getLatitude() == TrackRecordingService.PAUSE_LATITUDE) {
|
if (location.getLatitude() == PAUSE_LATITUDE) {
|
||||||
if (lastLocation != null && lastMovingLocation != null
|
if (lastLocation != null && lastMovingLocation != null
|
||||||
&& lastLocation != lastMovingLocation) {
|
&& lastLocation != lastMovingLocation) {
|
||||||
currentSegment.addTotalDistance(lastMovingLocation.distanceTo(lastLocation));
|
currentSegment.addTotalDistance(lastMovingLocation.distanceTo(lastLocation));
|
||||||
@@ -173,11 +169,11 @@ public class TripStatisticsUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double movingDistance = lastMovingLocation.distanceTo(location);
|
double movingDistance = lastMovingLocation.distanceTo(location);
|
||||||
if (movingDistance < minRecordingDistance) {
|
if (movingDistance < minRecordingDistance
|
||||||
if (!location.hasSpeed() || location.getSpeed() < MAX_NO_MOVEMENT_SPEED) {
|
&& (!location.hasSpeed() || location.getSpeed() < MAX_NO_MOVEMENT_SPEED)) {
|
||||||
lastLocation = location;
|
speedBuffer.reset();
|
||||||
return;
|
lastLocation = location;
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
long movingTime = location.getTime() - lastLocation.getTime();
|
long movingTime = location.getTime() - lastLocation.getTime();
|
||||||
if (movingTime < 0) {
|
if (movingTime < 0) {
|
||||||
@@ -203,7 +199,7 @@ public class TripStatisticsUpdater {
|
|||||||
updateSpeed(
|
updateSpeed(
|
||||||
location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
|
location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
|
||||||
}
|
}
|
||||||
|
|
||||||
lastLocation = location;
|
lastLocation = location;
|
||||||
lastMovingLocation = location;
|
lastMovingLocation = location;
|
||||||
}
|
}
|
||||||
@@ -231,13 +227,15 @@ public class TripStatisticsUpdater {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void updateSpeed(long time, double speed, long lastLocationTime, double lastLocationSpeed) {
|
void updateSpeed(long time, double speed, long lastLocationTime, double lastLocationSpeed) {
|
||||||
if (!isValidSpeed(time, speed, lastLocationTime, lastLocationSpeed)) {
|
if (speed < MAX_NO_MOVEMENT_SPEED) {
|
||||||
|
speedBuffer.reset();
|
||||||
|
} else if (isValidSpeed(time, speed, lastLocationTime, lastLocationSpeed)) {
|
||||||
|
speedBuffer.setNext(speed);
|
||||||
|
if (speed > currentSegment.getMaxSpeed()) {
|
||||||
|
currentSegment.setMaxSpeed(speed);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Log.d(TAG, "Invalid speed. speed: " + speed + " lastLocationSpeed: " + lastLocationSpeed);
|
Log.d(TAG, "Invalid speed. speed: " + speed + " lastLocationSpeed: " + lastLocationSpeed);
|
||||||
return;
|
|
||||||
}
|
|
||||||
speedBuffer.setNext(speed);
|
|
||||||
if (speed > currentSegment.getMaxSpeed()) {
|
|
||||||
currentSegment.setMaxSpeed(speed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user