From ecba2f7f7869083b315c2d7d40adce1db1e9d13a Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 24 Jan 2018 23:41:20 +0100 Subject: [PATCH] fix Speed cameras are announced 2 times #3967 --- .../net/osmand/plus/helpers/WaypointHelper.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index a2b539efac..4417556762 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -68,6 +68,7 @@ public class WaypointHelper { public static final int ALARMS = 4; public static final int MAX = 5; public static final int[] SEARCH_RADIUS_VALUES = {50, 100, 200, 500, 1000, 2000, 5000}; + private static final double DISTANCE_IGNORE_DOUBLE_SPEEDCAMS = 150; private List> locationPoints = new ArrayList>(); private ConcurrentHashMap locationPointsStates = new ConcurrentHashMap(); @@ -570,12 +571,20 @@ public class WaypointHelper { private void calculateAlarms(RouteCalculationResult route, List array, ApplicationMode mode) { + AlarmInfo prevSpeedCam = null; for (AlarmInfo i : route.getAlarmInfo()) { if (i.getType() == AlarmInfoType.SPEED_CAMERA) { if (app.getSettings().SHOW_CAMERAS.getModeValue(mode) || app.getSettings().SPEAK_SPEED_CAMERA.getModeValue(mode)) { LocationPointWrapper lw = new LocationPointWrapper(route, ALARMS, i, 0, i.getLocationIndex()); - lw.setAnnounce(app.getSettings().SPEAK_SPEED_CAMERA.get()); - array.add(lw); + if(prevSpeedCam != null && prevSpeedCam.getType() == AlarmInfoType.SPEED_CAMERA && + MapUtils.getDistance(prevSpeedCam.getLatitude(), prevSpeedCam.getLongitude(), + i.getLatitude(), i.getLongitude()) < DISTANCE_IGNORE_DOUBLE_SPEEDCAMS) { + // ignore double speed cams + } else { + lw.setAnnounce(app.getSettings().SPEAK_SPEED_CAMERA.get()); + array.add(lw); + prevSpeedCam = i; + } } } else { if (app.getSettings().SHOW_TRAFFIC_WARNINGS.getModeValue(mode) || app.getSettings().SPEAK_TRAFFIC_WARNINGS.getModeValue(mode)) { @@ -584,6 +593,7 @@ public class WaypointHelper { array.add(lw); } } + }