Code example for Location

Methods: getAccuracygetProvidergetTime

0
            return location1;
        } else if (location1 == null) {
            return location2;
        } else { 
            int location1Score =
                (int) (getLocationAge(location1) + location1.getAccuracy());
            int location2Score =
                (int) (getLocationAge(location2) + location2.getAccuracy());
 
            if (location1Score <= location2Score) {
                Log.d(TAG, location1.getProvider() + " won");
                return location1;
            } 
            return location2;
        } 
    } 
 
    private void reportLocationFound(Location location) {
        Log.d(TAG, "reportLocationFound");
        if (mMyLocationFoundListener != null) {
            mMyLocationFoundListener.onMyLocationFound(location);
        } 
    } 
 
    /** 
     * Is the provided {@link Location} accepted? 
     * @param location the location 
     * @return <code>true</code> if accepted <code>false</code> otherwise 
     */ 
    public boolean shouldAcceptLocation(Location location) {
        if (location == null)
            return false; 
 
        long timeSinceUpdate = System.currentTimeMillis() - location.getTime();
        if (timeSinceUpdate <= ACCEPTED_LOCATION_AGE_MILLIS 
                && location.getAccuracy() <= ACCEPTED_LOCATION_ACCURACY_METERS) {
            return true; 
        } 
        return false; 
    } 
 
    public int getLocationAge(Location location) {
        return (int) ((System.currentTimeMillis() - location.getTime()) / 1000);
    } 
 
    /** 
     * Used for receiving notifications from the LocationManager when the  
     * location has changed.