diff options
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/geopoint/Geopoint.java | 10 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/geopoint/GeopointFormatter.java | 45 |
2 files changed, 40 insertions, 15 deletions
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java index c03a2bc..dbe0aa4 100644 --- a/main/src/cgeo/geocaching/geopoint/Geopoint.java +++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java @@ -173,6 +173,16 @@ public final class Geopoint implements ICoordinates, Parcelable { return longitude; } + /* + * Return a waypoint which is the copy of this one rounded to the given limit. + * For example, to get a waypoint adapter to a display with 3 digits after the + * seconds decimal point, a rounding factor of 3600*1000 would be appropriate. + */ + Geopoint roundedAt(final long factor) { + return new Geopoint(((double) Math.round(latitude * factor)) / factor, + ((double) Math.round(longitude * factor)) / factor); + } + /** * Get longitude in microdegree. * diff --git a/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java b/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java index ba0a4d5..67f5ebb 100644 --- a/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java +++ b/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java @@ -64,36 +64,51 @@ public class GeopointFormatter { case LAT_LON_DECDEGREE_COMMA: return String.format((Locale) null, "%.6f,%.6f", latSigned, lonSigned); - case LAT_LON_DECMINUTE: + case LAT_LON_DECMINUTE: { + final Geopoint rgp = gp.roundedAt(60 * 1000); return String.format(Locale.getDefault(), "%c %02d° %06.3f · %c %03d° %06.3f", - gp.getLatDir(), gp.getLatDeg(), gp.getLatMinRaw(), gp.getLonDir(), gp.getLonDeg(), gp.getLonMinRaw()); + rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw(), rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); + } - case LAT_LON_DECMINUTE_RAW: + case LAT_LON_DECMINUTE_RAW: { + final Geopoint rgp = gp.roundedAt(60 * 1000); return String.format((Locale) null, "%c %02d° %06.3f %c %03d° %06.3f", - gp.getLatDir(), gp.getLatDeg(), gp.getLatMinRaw(), gp.getLonDir(), gp.getLonDeg(), gp.getLonMinRaw()); + rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw(), rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); + } - case LAT_LON_DECSECOND: + case LAT_LON_DECSECOND: { + final Geopoint rgp = gp.roundedAt(3600 * 1000); return String.format(Locale.getDefault(), "%c %02d° %02d' %06.3f\" · %c %03d° %02d' %06.3f\"", - gp.getLatDir(), gp.getLatDeg(), gp.getLatMin(), gp.getLatSecRaw(), - gp.getLonDir(), gp.getLonDeg(), gp.getLonMin(), gp.getLonSecRaw()); + rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMin(), rgp.getLatSecRaw(), + rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMin(), rgp.getLonSecRaw()); + } case LAT_DECDEGREE_RAW: return String.format((Locale) null, "%.6f", latSigned); - case LAT_DECMINUTE: - return String.format(Locale.getDefault(), "%c %02d° %06.3f", gp.getLatDir(), gp.getLatDeg(), gp.getLatMinRaw()); + case LAT_DECMINUTE: { + final Geopoint rgp = gp.roundedAt(60 * 1000); + return String.format(Locale.getDefault(), "%c %02d° %06.3f", rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw()); + } - case LAT_DECMINUTE_RAW: - return String.format(Locale.getDefault(), "%c %02d %06.3f", gp.getLatDir(), gp.getLatDeg(), gp.getLatMinRaw()); + case LAT_DECMINUTE_RAW: { + final Geopoint rgp = gp.roundedAt(60 * 1000); + return String.format(Locale.getDefault(), "%c %02d %06.3f", rgp.getLatDir(), rgp.getLatDeg(), rgp.getLatMinRaw()); + } case LON_DECDEGREE_RAW: return String.format((Locale) null, "%.6f", lonSigned); - case LON_DECMINUTE: - return String.format(Locale.getDefault(), "%c %03d° %06.3f", gp.getLonDir(), gp.getLonDeg(), gp.getLonMinRaw()); + case LON_DECMINUTE: { + final Geopoint rgp = gp.roundedAt(60 * 1000); + return String.format(Locale.getDefault(), "%c %03d° %06.3f", rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); + } + + case LON_DECMINUTE_RAW: { + final Geopoint rgp = gp.roundedAt(60 * 1000); + return String.format(Locale.getDefault(), "%c %03d %06.3f", rgp.getLonDir(), rgp.getLonDeg(), rgp.getLonMinRaw()); + } - case LON_DECMINUTE_RAW: - return String.format(Locale.getDefault(), "%c %03d %06.3f", gp.getLonDir(), gp.getLonDeg(), gp.getLonMinRaw()); default: throw new IllegalArgumentException(); } |
