trying to get rid of implausible locations delivered by the network provider

This commit is contained in:
y20k 2016-09-28 14:57:06 +02:00
parent 046228702a
commit f02addae4c
6 changed files with 38 additions and 11 deletions

View file

@ -25,6 +25,6 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'org.osmdroid:osmdroid-android:5.2@aar'
compile 'org.osmdroid:osmdroid-android:5.4.1:release@aar'
compile 'com.google.code.gson:gson:2.7'
}

View file

@ -372,6 +372,8 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys, Di
startService(intent);
} else {
// TODO ask if user wants to save the last track before starting a new recording
// TODO alternatively only ask if last track was very short
// show snackbar
Snackbar.make(view, R.string.snackbar_message_tracking_started, Snackbar.LENGTH_SHORT).setAction("Action", null).show();

View file

@ -396,6 +396,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
// save track object
SaveTrackAsyncHelper saveTrackAsyncHelper = new SaveTrackAsyncHelper();
saveTrackAsyncHelper.execute();
// TODO add toast indicating track save
}
@ -587,7 +588,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
/**
* Inner class: Saves track to external storage using an AsyncTask
* Inner class: Saves track to external storage using AsyncTask
*/
private class SaveTrackAsyncHelper extends AsyncTask<Void, Void, Void> {

View file

@ -250,7 +250,17 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
} else {
// get last WayPoint and compare it to current location
Location lastWayPoint = mTrack.getWayPointLocation(trackSize - 1);
if (LocationHelper.isNewWayPoint(lastWayPoint, mCurrentBestLocation)) {
// compute average speed
float averageSpeed = 0f;
if (trackSize > 1) {
Location firstWayPoint = mTrack.getWayPointLocation(0);
float distance = firstWayPoint.distanceTo(lastWayPoint);
long timeDifference = lastWayPoint.getElapsedRealtimeNanos() - firstWayPoint.getElapsedRealtimeNanos();
averageSpeed = distance / ((float)timeDifference / ONE_NANOSECOND);
}
if (LocationHelper.isNewWayPoint(lastWayPoint, mCurrentBestLocation, averageSpeed)) {
// if new, add current best location to track
newWayPoint = mTrack.addWayPoint(mCurrentBestLocation);
}

View file

@ -136,19 +136,33 @@ public final class LocationHelper implements TrackbookKeys {
/* Checks if given location is a new WayPoint */
public static boolean isNewWayPoint(Location lastLocation, Location newLocation) {
public static boolean isNewWayPoint(Location lastLocation, Location newLocation, float averageSpeed) {
float distance = newLocation.distanceTo(lastLocation);
long timeDifference = newLocation.getElapsedRealtimeNanos() - lastLocation.getElapsedRealtimeNanos();
// TODO check for sudden location jump errors
if (newLocation.getProvider().equals(LocationManager.NETWORK_PROVIDER)) {
// SPECIAL CASE network: plausibility check for network provider. looking for sudden location jump errors
float speedDifference;
float currentSpeed = distance / ((float)timeDifference / ONE_NANOSECOND);
if (currentSpeed > averageSpeed) {
speedDifference = currentSpeed / averageSpeed;
} else {
speedDifference = averageSpeed / currentSpeed;
}
// check if speed is high (10 m/s == 36km/h) and has doubled
if (averageSpeed != 0f && currentSpeed > 10f && speedDifference > 2f) {
// implausible location
return false;
}
// DEFAULT network: distance is bigger than 50 meters and time difference bigger than 12 seconds
return distance > 50 && timeDifference >= 12 * ONE_NANOSECOND;
if (newLocation.getProvider().equals(LocationManager.GPS_PROVIDER)) {
// CASE GPS: distance is bigger than 10 meters and time difference bigger than 12 seconds
return distance > 10 && timeDifference >= TWELVE_SECONDS_IN_NANOSECONDS;
} else {
// CASE network: distance is bigger than 50 meters and time difference bigger than 12 seconds
return distance > 50 && timeDifference >= TWELVE_SECONDS_IN_NANOSECONDS;
// DEFAULT GPS: distance is bigger than 10 meters and time difference bigger than 12 seconds
return distance > 10 && timeDifference >= 12 * ONE_NANOSECOND;
}
}

View file

@ -67,11 +67,11 @@ public interface TrackbookKeys {
/* RESULTS */
/* CONSTANTS */
long ONE_NANOSECOND = 1000000000L;
long EIGHT_HOURS_IN_MILLISECONDS = 43200000; // maximum tracking duration
long FIFTEEN_SECONDS_IN_MILLISECONDS = 15000; // timer interval for tracking
long FIVE_MINUTES_IN_NANOSECONDS = 5L * 60000000000L; // determines a stop over
long TWO_MINUTES_IN_NANOSECONDS = 2L * 60000000000L; // defines an old location
long TWELVE_SECONDS_IN_NANOSECONDS = 12000000000L; // defines a new location
/* MISC */