Code example for Location

Methods: getProvidergetTime

0
    public static Location selectBetterLocation(Location location1, Location location2) {
        if (location1 == null) return location2;
        else if (location2 == null) return location1;
        else { 
            long time1 = location1.getTime();
            long time2 = location2.getTime();
 
            boolean firstFine = isFineLocation(location1);
            boolean secondFine = isFineLocation(location2);
 
            if (firstFine && !secondFine) {
                time1 += FINE_LOCATION_TIME_ADVANTAGE;
            } else if (!firstFine && secondFine) {
                time2 += FINE_LOCATION_TIME_ADVANTAGE;
            } 
 
            if (time1 > time2) return location1;
            else return location2;
        } 
    } 
 
    public static boolean isFineLocation(Location location) {
        return location.getProvider().equalsIgnoreCase("gps");
    } 
}