From ef8d23593daed17486f19b1d5f16b2e7798c580f Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 7 Apr 2013 10:45:42 +0200 Subject: fix #2686: waypoint from notes are duplicated upon refresh --- main/src/cgeo/geocaching/Geocache.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'main/src/cgeo/geocaching/Geocache.java') 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) -- cgit v1.1