Code example for Location

Methods: getAccuracygetProvidergetTime

0
    } 
 
    public void onLocationChanged(Location location) {
        if (isBetterLocation(location)) {
            LOG_YBO.debug("Mise à jour de la loc : " + currentBestLocation);
            listenner.updateLocation(currentBestLocation);
        } 
    } 
 
    public void onProviderDisabled(String provider) {
    } 
 
    public void onProviderEnabled(String provider) {
    } 
 
    public void onStatusChanged(String provider, int status, Bundle extras) {
    } 
 
    private static final long FIVE_MINUTES = 1000 * 60 * 5;
 
    /** 
     * Determines whether one Location reading is better than the current 
     * Location fix 
     * 
     * @param location The new Location that you want to evaluate 
     * @return true is location is best than the location receive before. 
     */ 
    private boolean isBetterLocation(Location location) {
        if (location == null) {
            return false; 
        } 
        LOG_YBO.debug("BestLocation : " + location);
        if (currentBestLocation == null) {
            // A new location is always better than no location 
            currentBestLocation = location;
            LOG_YBO.debug("BestLocation : true (ancienne null)");
            return true; 
        } 
 
        // Check whether the new location fix is newer or older 
        long timeDelta = location.getTime() - currentBestLocation.getTime();
        boolean isSignificantlyNewer = timeDelta > FIVE_MINUTES;
        boolean isSignificantlyOlder = timeDelta < -FIVE_MINUTES;
        boolean isNewer = timeDelta > 0;
 
        // If it's been more than two minutes since the current location, use 
        // the new location 
        // because the user has likely moved 
        if (isSignificantlyNewer) {
            currentBestLocation = location;
            LOG_YBO.debug("BestLocation : true (plus recente)");
            return true; 
            // If the new location is more than two minutes older, it must be 
            // worse 
        } else if (isSignificantlyOlder) {
            LOG_YBO.debug("BestLocation : false (trop vieille)");
            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;
        boolean isSignificantlyLessAccurate = accuracyDelta > 200;
 
        // Check if the old and new location are from the same provider 
        boolean isFromSameProvider = isSameProvider(location.getProvider(), currentBestLocation.getProvider());
 
        // Determine location quality using a combination of timeliness and 
        // accuracy 
        if (isMoreAccurate) {
            currentBestLocation = location;