diff --git a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java index 23784ec5ea..f7b4cf89c3 100644 --- a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java @@ -9,6 +9,8 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; +import net.osmand.Location; + public class RouteDataObject { /*private */static final int RESTRICTION_SHIFT = 3; @@ -409,7 +411,16 @@ public class RouteDataObject { // So it should be fix in both places return directionRoute(startPoint, plus, 5); } - + + public boolean bearingVsRouteDirection(Location loc) { + boolean direction = true; + if(loc != null && loc.hasBearing()) { + double diff = MapUtils.alignAngleDifference(directionRoute(0, true) - loc.getBearing() / 180f * Math.PI); + direction = Math.abs(diff) < Math.PI / 2f; + } + return direction; + } + public double distance(int startPoint, int endPoint) { if(startPoint > endPoint) { int k = endPoint; diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index f9a8d46e77..0b3df031cb 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -262,13 +262,7 @@ public class WaypointHelper { } public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc, boolean showCameras) { - boolean direction = true; - if (loc.hasBearing()) { - double diff = MapUtils.alignAngleDifference(ro.directionRoute(0, true) - - loc.getBearing() / 180f * Math.PI); - direction = Math.abs(diff) < Math.PI / 2f; - } - float mxspeed = ro.getMaximumSpeed(direction); + float mxspeed = ro.getMaximumSpeed(ro.bearingVsRouteDirection(loc)); float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f; AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta); if (speedAlarm != null) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 7e290b957e..95437225ff 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -390,14 +390,7 @@ public class RouteInfoWidgetsFactory { && trackingUtilities.isMapLinkedToLocation()) { RouteDataObject ro = locationProvider.getLastKnownRouteSegment(); if(ro != null) { - boolean direction = true; - Location loc = locationProvider.getLastKnownLocation(); - if(loc != null && loc.hasBearing()) { - double diff = MapUtils.alignAngleDifference(ro.directionRoute(0, true) - - loc.getBearing() / 180f * Math.PI); - direction = Math.abs(diff) < Math.PI / 2f; - } - mx = ro.getMaximumSpeed(direction); + mx = ro.getMaximumSpeed(ro.bearingVsRouteDirection(locationProvider.getLastKnownLocation())); } } else if (rh != null) { mx = rh.getCurrentMaxSpeed();