private void drawHistory(@Nullable final Location currentLoc) {
        // only draw if position history is currently enabled. Remove possible old history line if not.
        if (!Settings.isMapTrail()) {
            removePath();
            return;
        }

        final PositionHistory history = viewModel.positionHistory.getValue();

        // only draw if position history is non-empty. Remove possible old history line if not.
        if (history == null || history.getHistory().isEmpty()) {
            removePath();
            return;
        }

        final ArrayList<TrailHistoryElement> historyElements = history.getHistory();
        final GeoGroup.Builder geoGroup = GeoGroup.builder();

        ArrayList<Geopoint> segmentPoints = new ArrayList<>();

        segmentPoints.add(new Geopoint(historyElements.get(0).getLocation()));
        for (int i = 1; i < historyElements.size(); i++) {
            if (historyElements.get(i).getLocation().distanceTo(historyElements.get(i - 1).getLocation()) > LINE_MAXIMUM_DISTANCE_METERS) {
                geoGroup.addItems(GeoPrimitive.createPolyline(segmentPoints, lineStyle));
                segmentPoints = new ArrayList<>();
            }
            segmentPoints.add(new Geopoint(historyElements.get(i).getLocation()));
        }
        // always add current position
        if (currentLoc != null) {
            segmentPoints.add(new Geopoint(currentLoc));
        }
        geoGroup.addItems(GeoPrimitive.createPolyline(segmentPoints, lineStyle).buildUpon().setZLevel(LayerHelper.ZINDEX_HISTORY).build());

        layer.put(KEY_HISTORY_LINE, geoGroup.build());
        pathStored = true;
    }
maximum distance (in meters) up to which two points in the trail get connected by a drawn line
main/src/main/java/cgeo/geocaching/unifiedmap/layers/PositionHistoryLayer.java