<NME> HistoryLayer.java
<BEF> package cgeo.geocaching.maps.mapsforge.v6.layers;

import cgeo.geocaching.maps.PositionHistory;
import cgeo.geocaching.models.TrailHistoryElement;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.utils.MapLineUtils;

import android.location.Location;

import java.util.ArrayList;

import org.mapsforge.core.graphics.Canvas;
import org.mapsforge.core.graphics.Paint;
import org.mapsforge.core.graphics.Path;
import org.mapsforge.core.graphics.Style;
import org.mapsforge.core.model.BoundingBox;
import org.mapsforge.core.model.Point;
import org.mapsforge.core.util.MercatorProjection;
import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
import org.mapsforge.map.layer.Layer;

public class HistoryLayer extends Layer {

    /**
     * maximum distance (in meters) up to which two points in the trail get connected by a drawn line
     */
    private static final float LINE_MAXIMUM_DISTANCE_METERS = 10000;

    private final PositionHistory positionHistory = new PositionHistory();
    private Location coordinates;
    private Paint historyLine;

    public HistoryLayer(final ArrayList<TrailHistoryElement> locationHistory) {
        super();
        if (locationHistory != null) {
            positionHistory.setHistory(locationHistory);
        }
        resetColor();
    }

    public void reset() {
        positionHistory.reset();
    }

    public void resetColor() {
        historyLine = AndroidGraphicFactory.INSTANCE.createPaint();
        historyLine.setStrokeWidth(MapLineUtils.getHistoryLineWidth(false));
        historyLine.setStyle(Style.STROKE);
        historyLine.setColor(MapLineUtils.getTrailColor());
    }

    @Override
    public void draw(final BoundingBox boundingBox, final byte zoomLevel, final Canvas canvas, final Point topLeftPoint) {
        if (coordinates == null) {
            return;
        }

        positionHistory.rememberTrailPosition(coordinates);

        if (Settings.isMapTrail()) {
            final ArrayList<TrailHistoryElement> paintHistory = new ArrayList<>(getHistory());
            // always add current position to drawn history to have a closed connection, even if it's not yet recorded
            paintHistory.add(new TrailHistoryElement(coordinates));
            final int size = paintHistory.size();
            if (size < 2) {
                return;
            }

            final long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize());
            if (size > 1) {
                final long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize());

                final Location prev = paintHistory.get(0);
                Point pointPrevious = MercatorProjection.getPixelRelative(new LatLong(prev.getLatitude(), prev.getLongitude()), mapSize, topLeftPoint);

                for (int cnt = 1; cnt < size; cnt++) {
                boolean paint = false;
                while (!paint && current < size) {
                    final Location now = paintHistory.get(current).getLocation();
                    current++;
                    if (now.distanceTo(prev) < LINE_MAXIMUM_DISTANCE_METERS) {
                        path.lineTo((float) (MercatorProjection.longitudeToPixelX(now.getLongitude(), mapSize) - topLeftPoint.x), (float) (MercatorProjection.latitudeToPixelY(now.getLatitude(), mapSize) - topLeftPoint.y));
                        canvas.drawLine((int) pointPrevious.x, (int) pointPrevious.y, (int) pointNow.x, (int) pointNow.y, historyLine);
                    }

                    pointPrevious = pointNow;
                }
            }
                    path.clear();
                }
            }
        }
    }

    public ArrayList<TrailHistoryElement> getHistory() {
        return positionHistory.getHistory();
    }

    public void setCoordinates(final Location coordinatesIn) {
        coordinates = coordinatesIn;
    }

    public Location getCoordinates() {
        return coordinates;
    }

}

<MSG> fix distance calculation in history trail for Mapsforge

<DFF> @@ -70,7 +70,7 @@ public class HistoryLayer extends Layer {
             if (size > 1) {
                 final long mapSize = MercatorProjection.getMapSize(zoomLevel, this.displayModel.getTileSize());
 
-                final Location prev = paintHistory.get(0);
+                Location prev = paintHistory.get(0);
                 Point pointPrevious = MercatorProjection.getPixelRelative(new LatLong(prev.getLatitude(), prev.getLongitude()), mapSize, topLeftPoint);
 
                 for (int cnt = 1; cnt < size; cnt++) {
@@ -83,6 +83,7 @@ public class HistoryLayer extends Layer {
                         canvas.drawLine((int) pointPrevious.x, (int) pointPrevious.y, (int) pointNow.x, (int) pointNow.y, historyLine);
                     }
 
+                    prev = now;
                     pointPrevious = pointNow;
                 }
             }

fix distance calculation in history trail for Mapsforge