private void saveCachedDistances(final ArrayList<RouteItem> route) {
        resetCachedDistances();
        for (int i = 0; i < route.size(); i++) {
            for (int j = 0; j < route.size(); j++) {
                if (i != j && distanceMatrix[i][j] != Integer.MAX_VALUE) {
                    cachedDistances.distances.put(getCacheKey(initialRoute.get(i).getPoint(), initialRoute.get(j).getPoint()), distanceMatrix[i][j]);
                }
            }
        }
        try {
            new ObjectMapper().writeValue(new File(LocalStorage.getFirstExternalPrivateCgeoDirectory(), CACHED_DISTANCES_FILENAME), cachedDistances);
        } catch (final IOException e) {
            Log.w("Error writing tsp cache file: " + e.getMessage());
        }
    }
returns length in meters for the given route
main/src/main/java/cgeo/geocaching/maps/routing/RouteOptimizationHelper.java