diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2013-04-07 10:45:42 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2013-04-07 10:45:42 +0200 |
| commit | ef8d23593daed17486f19b1d5f16b2e7798c580f (patch) | |
| tree | 0664ba045d9e05c7a5fd01eaaebaf2a3b4d14094 /main/src/cgeo/geocaching/Geocache.java | |
| parent | 7996ca3eb882e3cdf78c9b62a4c7e4b48e3c42e2 (diff) | |
| download | cgeo-ef8d23593daed17486f19b1d5f16b2e7798c580f.zip cgeo-ef8d23593daed17486f19b1d5f16b2e7798c580f.tar.gz cgeo-ef8d23593daed17486f19b1d5f16b2e7798c580f.tar.bz2 | |
fix #2686: waypoint from notes are duplicated upon refresh
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 9a8325d..2706c5b 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -1372,8 +1372,11 @@ public class Geocache implements ICache, IWaypoint { while (matcher.find()) { try { final Geopoint point = new Geopoint(note.substring(matcher.start())); - // coords must have non zero latitude and longitude and at least one part shall have fractional degrees - if (point.getLatitudeE6() != 0 && point.getLongitudeE6() != 0 && ((point.getLatitudeE6() % 1000) != 0 || (point.getLongitudeE6() % 1000) != 0)) { + // Coords must have non zero latitude and longitude, at least one part shall have fractional degrees, + // and there must exist no waypoint with the same coordinates already. + if (point.getLatitudeE6() != 0 && point.getLongitudeE6() != 0 && + ((point.getLatitudeE6() % 1000) != 0 || (point.getLongitudeE6() % 1000) != 0) && + !hasIdenticalWaypoint(point)) { final String name = cgeoapplication.getInstance().getString(R.string.cache_personal_note) + " " + count; final Waypoint waypoint = new Waypoint(name, WaypointType.WAYPOINT, false); waypoint.setCoords(point); @@ -1392,6 +1395,15 @@ public class Geocache implements ICache, IWaypoint { } } + private boolean hasIdenticalWaypoint(final Geopoint point) { + for (final Waypoint waypoint: waypoints) { + if (waypoint.getCoords() == point) { + return true; + } + } + return false; + } + /* * For working in the debugger * (non-Javadoc) |
