package cgeo.geocaching.maps;

import cgeo.geocaching.location.Geopoint;

import android.graphics.Canvas;
import android.location.Location;
import android.view.View;

public class DistanceDrawer {
    private final Geopoint destinationCoords;

    private float distance = 0.0f;
    private float realDistance = 0.0f;
    private boolean showBothDistances = false;
    private float routeDistance = 0.0f;

    private final MapDistanceDrawerCommons mapDistanceDrawer;

    public DistanceDrawer(final View root, final Geopoint destinationCoords, final boolean showBothDistances) {
        this.destinationCoords = destinationCoords;
        this.showBothDistances = showBothDistances;
        mapDistanceDrawer = new MapDistanceDrawerCommons(root);
    }

    public void setCoordinates(final Location location) {
        final Geopoint currentCoords = new Geopoint(location);
        distance = null != destinationCoords ? currentCoords.distanceTo(destinationCoords) : 0.0f;
    }

    public Geopoint getDestinationCoords() {
        return destinationCoords;
    }

    public void setRealDistance(final float realDistance) {
        this.realDistance = realDistance;
    }

    public void setRouteDistance(final float routeDistance) {
        this.routeDistance = routeDistance;
    }

    public void drawDistance(final Canvas canvas) {
        mapDistanceDrawer.drawDistance(showBothDistances, distance, realDistance);
        mapDistanceDrawer.drawRouteDistance(routeDistance);
    }
}

@@ -819,38 +819,31 @@
     
-final Geopoint current
+if (destination
 Coords =
  new
@@ -842,93 +842,129 @@
 ds =
+=
  n
-ew Geopoint(location);%0A        distance = null != destinationCoords ? currentCoords
+ull %7C%7C location == null) %7B%0A            distance = 0.0f;%0A        %7D else %7B%0A            distance = new Geopoint(location)
 .dis
@@ -993,17 +993,21 @@
 rds)
- : 0.0f;%0A
+;%0A        %7D%0A 
     

fix #10195: add npe safeguard to DistanceViewer