Skip to content

Commit

Permalink
Trying out some logic to continue logging for the user-specified retr…
Browse files Browse the repository at this point in the history
…y interval, and picking out the most accurate point.

Issue #453
Issue #591
Issue #654
  • Loading branch information
mendhak committed Mar 1, 2024
1 parent ca58c13 commit 92e98ce
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,40 @@ void onLocationChanged(Location loc) {
//Success, reset timestamp for next time.
session.setFirstRetryTimeStamp(0);
}

// else if(preferenceHelper.shouldGetBestPossibleAccuracy()) {
else if(true) {
//If the user wants the best possible accuracy, store the point, only if it's the best so far.
// Then retry until the time limit is reached.

if(session.getFirstRetryTimeStamp() == 0){
//It's the first loop so reset timestamp and temporary location
session.setTemporaryLocationForBestAccuracy(null);
session.setFirstRetryTimeStamp(System.currentTimeMillis());
}

if(session.getTemporaryLocationForBestAccuracy() == null || loc.getAccuracy() < session.getTemporaryLocationForBestAccuracy().getAccuracy()){
LOG.info("New point with accuracy of " + String.valueOf(loc.getAccuracy()) + " m." );
session.setTemporaryLocationForBestAccuracy(loc);
}

if (currentTimeStamp - session.getFirstRetryTimeStamp() <= preferenceHelper.getLoggingRetryPeriod() * 1000) {
// return and keep trying
return;
}

if (currentTimeStamp - session.getFirstRetryTimeStamp() > preferenceHelper.getLoggingRetryPeriod() * 1000) {
// We've reached the end of the retry period, use the best point we've got so far.
LOG.debug("Retry timeout reached, using best point so far with accuracy of " + String.valueOf(session.getTemporaryLocationForBestAccuracy().getAccuracy()) + " m.");
loc = session.getTemporaryLocationForBestAccuracy();

//reset for next time
session.setTemporaryLocationForBestAccuracy(null);
session.setFirstRetryTimeStamp(0);

}

}
}

//Don't do anything until the user-defined distance has been traversed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class Session {
private Location previousLocationInfo;
private Location currentLocationInfo;

private Location temporaryLocationForBestAccuracy;

private Session() {

}
Expand Down Expand Up @@ -375,6 +377,19 @@ public long getFirstRetryTimeStamp() {
}


/**
* When retrying to get best accuracy, this can store a location object representing the best so far.
* @param loc
*/
public void setTemporaryLocationForBestAccuracy(Location loc) {
temporaryLocationForBestAccuracy = loc;
}


/**
* Returns the temporary location, stored for best accuracy
* @return
*/
public Location getTemporaryLocationForBestAccuracy() {
return temporaryLocationForBestAccuracy;
}
}

0 comments on commit 92e98ce

Please sign in to comment.