@Override
    protected int compareCaches(final Geocache cache1, final Geocache cache2) {
        final Float distance1 = cache1.getDistance();
        final Float distance2 = cache2.getDistance();
        if (distance1 == null) {
            return distance2 == null ? 0 : 1;
        }
        return distance2 == null ? -1 : Float.compare(distance1, distance2);
    }
sorts caches by distance to given position
main/src/main/java/cgeo/geocaching/sorting/AbstractDistanceComparator.java