agro6162 / talkmyphone

Automatically exported from code.google.com/p/talkmyphone
0 stars 0 forks source link

GPS updates too often #98

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The GPS does update too often for my taste, seems like twice a second.

Problem seems to be, that a accuracy delta (change) of 0 results in a better 
location and then there no timeout where there doesn't need to be an update if 
the position didn't change.

Anyhow, the following isBetterLocation did work quite well for me, I thought I 
might share.

protected boolean isBetterLocation(Location location, Location 
currentBestLocation) {        
        if (currentBestLocation == null) {
            // A new location is always better than no location
            return true;
        }

        // Check whether the new location fix is newer or older
        long timeDelta = location.getTime() - currentBestLocation.getTime();
        boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
        boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
        boolean isNewer = timeDelta > 0;
        boolean isAnnoying = timeDelta < TWO_MINUTES;   // Do not send me to many locationupdates

        // If it's been more than two minutes since the current location, use the new location
        // because the user has likely moved
        if (isSignificantlyNewer) {
            return true;
        // If the new location is more than two minutes older, it must be worse
        } else if (isSignificantlyOlder) {
            return false;
        }

        // Check whether the new location fix is more or less accurate
        int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
        boolean isLessAccurate = accuracyDelta > 0;
        boolean isMoreAccurate = (accuracyDelta < 0) && (accuracyDelta != 0) ;
        // Determine location quality using a combination of timeliness and accuracy
        if (isMoreAccurate) {
            return true;
        } else if (isNewer && !isLessAccurate && !isAnnoying) {
            return true;
        }
        return false;
    }

Original issue reported on code.google.com by anonym1970 on 13 Oct 2010 at 4:54

GoogleCodeExporter commented 9 years ago
Well, after reviewing, maybe a different approach for the frequency of updates 
would be better, like comparing the locations positions for a change before 
sending via XMPP instead of the two minute timer isAnnoying.

Original comment by anonym1970 on 13 Oct 2010 at 5:29