@Override
    public void beforeSort(final List<Geocache> list) {
        super.beforeSort(list);
        // calculate all distances only once to avoid costly re-calculation of the same distance during sorting
        for (final Geocache cache : list) {
            if (cache.getCoords() != null) {
                cache.setDistance(coords.distanceTo(cache.getCoords()));
            }
        }
    }
sorts caches by distance to given position
main/src/main/java/cgeo/geocaching/sorting/AbstractDistanceComparator.java