diff options
| author | TriakCZ <kunc88@gmail.com> | 2013-03-31 20:40:16 +0200 |
|---|---|---|
| committer | TriakCZ <kunc88@gmail.com> | 2013-03-31 20:40:16 +0200 |
| commit | ce094d31c0b234648cf38d1fa8d360cfed37a4f7 (patch) | |
| tree | cfae691f7d9e1012b0d4cf9bd22a02c8ad0af91b /main/src/cgeo/geocaching/ui | |
| parent | 32460d132a0906fd39e92c1ce1c5088920ddf23c (diff) | |
| download | cgeo-ce094d31c0b234648cf38d1fa8d360cfed37a4f7.zip cgeo-ce094d31c0b234648cf38d1fa8d360cfed37a4f7.tar.gz cgeo-ce094d31c0b234648cf38d1fa8d360cfed37a4f7.tar.bz2 | |
Displaying distance to waypoint on map popup
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CacheDetailsCreator.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java index e98bd77..80f01e2 100644 --- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java +++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java @@ -2,6 +2,7 @@ package cgeo.geocaching.ui; import cgeo.geocaching.Geocache; import cgeo.geocaching.R; +import cgeo.geocaching.Waypoint; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Units; @@ -154,4 +155,24 @@ public final class CacheDetailsCreator { } add(R.string.cache_distance, text); } + + public void addDistance(final Waypoint wpt, final TextView waypointDistanceView) { + Float distance = null; + if (wpt.getCoords() != null) { + final Geopoint currentCoords = cgeoapplication.getInstance().currentGeo().getCoords(); + if (currentCoords != null) { + distance = currentCoords.distanceTo(wpt); + } + } + String text = "--"; + if (distance != null) { + text = Units.getDistanceFromKilometers(distance); + } + else if (waypointDistanceView != null) { + // if there is already a distance in waypointDistance, use it instead of resetting to default. + // this prevents displaying "--" while waiting for a new position update (See bug #1468) + text = waypointDistanceView.getText().toString(); + } + add(R.string.cache_distance, text); + } } |
