diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2013-04-02 00:04:21 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2013-04-02 00:04:21 +0200 |
| commit | aed83ab4ecd896193d9662b6f91b2e285cead7e5 (patch) | |
| tree | 25fb5aa2f47e0665aaa36c64be707dee6884c74e /main/src | |
| parent | e703540659c2ba6480583d9819d96120d7b95a06 (diff) | |
| parent | 4603290a0a79498815fe8d1d80460e4c0e97fe2b (diff) | |
| download | cgeo-aed83ab4ecd896193d9662b6f91b2e285cead7e5.zip cgeo-aed83ab4ecd896193d9662b6f91b2e285cead7e5.tar.gz cgeo-aed83ab4ecd896193d9662b6f91b2e285cead7e5.tar.bz2 | |
Merge branch 'issue-2624' into upstream
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(); } |
