Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce excessive yawing during navigation #18688

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class Location {
private long mTime = 0;
private double mLatitude = 0.0;
private double mLongitude = 0.0;
private boolean mHasDestination = false;
private double mDestinationLatitude = 0.0;
private double mDestinationLongitude = 0.0;
private boolean mHasAltitude = false;
private double mAltitude = 0.0f;
private boolean mHasSpeed = false;
Expand Down Expand Up @@ -89,6 +92,9 @@ public void set(Location l) {
mTime = l.mTime;
mLatitude = l.mLatitude;
mLongitude = l.mLongitude;
mHasDestination = l.mHasDestination;
mDestinationLatitude = l.mDestinationLatitude;
mDestinationLongitude = l.mDestinationLongitude;
mHasAltitude = l.mHasAltitude;
mAltitude = l.mAltitude;
mHasSpeed = l.mHasSpeed;
Expand All @@ -109,6 +115,9 @@ public void reset() {
mTime = 0;
mLatitude = 0;
mLongitude = 0;
mHasDestination = false;
mDestinationLatitude = 0;
mDestinationLongitude = 0;
mHasAltitude = false;
mAltitude = 0;
mHasSpeed = false;
Expand Down Expand Up @@ -359,6 +368,36 @@ public void setLongitude(double longitude) {
mLongitude = longitude;
}

/**
* Returns true if the destination which corresponds to the bearing is available.
*/
public boolean hasDestination() {
return mHasDestination;
}

/**
* Returns the latitude of destination.
*/
public double getDestinationLatitude() {
return mDestinationLatitude;
}

/**
* Returns the longitude of destination.
*/
public double getDestinationLongitude() {
return mDestinationLongitude;
}

/**
* Sets the destination point.
*/
public void setDestination(double latitude, double longitude) {
mDestinationLatitude = latitude;
mDestinationLongitude = longitude;
mHasDestination = true;
}

/**
* Returns true if this fix contains altitude information, false
* otherwise.
Expand Down Expand Up @@ -456,6 +495,15 @@ public void setBearing(float bearing) {
}
mBearing = bearing;
mHasBearing = true;
mHasDestination = false;
}

/**
* Sets the bearing and the corresponding destination.
*/
public void setBearing(float bearing, double latitude, double longitude) {
setBearing(bearing);
setDestination(latitude, longitude);
}

/**
Expand All @@ -465,6 +513,7 @@ public void setBearing(float bearing) {
public void removeBearing() {
mBearing = 0.0f;
mHasBearing = false;
mHasDestination = false;
}

/**
Expand Down Expand Up @@ -541,6 +590,9 @@ public void removeVerticalAccuracy() {
",mTime=" + mTime +
",mLatitude=" + mLatitude +
",mLongitude=" + mLongitude +
",mHasDestination=" + mHasDestination +
",mDestinationLatitude=" + mDestinationLatitude +
",mDestinationLongitude=" + mDestinationLongitude +
",mHasAltitude=" + mHasAltitude +
",mAltitude=" + mAltitude +
",mHasSpeed=" + mHasSpeed +
Expand Down
14 changes: 12 additions & 2 deletions OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
private static final int AUTO_FOLLOW_MSG_ID = OsmAndConstants.UI_HANDLER_LOCATION_SERVICE + 4;
private static final long MOVE_ANIMATION_TIME = 500;
public static final int AUTO_ZOOM_DEFAULT_CHANGE_ZOOM = 4500;
public static final float MAX_DELTA_SMOOTH_BEARING = 20.0f;

private final OsmandApplication app;
private final OsmandSettings settings;
Expand Down Expand Up @@ -236,8 +237,17 @@ public void updateLocation(Location location) {
NativeUtilities.containsLatLon(mapRenderer, tb, location.getLatitude(), location.getLongitude()));
if (currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING) {
// special case when bearing equals to zero (we don't change anything)
if (location.hasBearing() && location.getBearing() != 0f) {
rotation = -location.getBearing();
if (location.hasBearing()) {
float shortBearing = -location.getBearing();
if (prevLocation != null && location.hasDestination()) {
Location nextLocation = new Location(
locationProvider,
location.getDestinationLatitude(),
location.getDestinationLongitude());
float longBearing = -MapUtils.normalizeDegrees360(prevLocation.bearingTo(nextLocation));
rotation = Math.abs(longBearing - shortBearing) < MAX_DELTA_SMOOTH_BEARING ? longBearing : shortBearing;
} else
rotation = shortBearing;
}
if (rotation == null && prevLocation != null && tb != null) {
double distDp = (tb.getPixDensity() * MapUtils.getDistance(prevLocation, location)) / tb.getDensity();
Expand Down
2 changes: 1 addition & 1 deletion OsmAnd/src/net/osmand/plus/routing/RoutingHelperUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static void approximateBearingIfNeeded(@NonNull RoutingHelper helper, @No
double projectDist = helper.getMaxAllowedProjectDist(loc);
if ((!loc.hasBearing() || Math.abs(loc.getBearing() - bearingTo) < MAX_BEARING_DEVIATION) &&
loc.distanceTo(locationProjection) < projectDist) {
locationProjection.setBearing(bearingTo);
locationProjection.setBearing(bearingTo, to.getLatitude(), to.getLongitude());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void setupLocation(@NonNull Triple<Boolean, Boolean, Boolean> triple,
}
if (previous != null && triple.getFirst()
&& previous.distanceTo(current) > 3 && (!realistic || speed >= 1)) {
current.setBearing(previous.bearingTo(current));
current.setBearing(previous.bearingTo(current), current.getLatitude(), current.getLongitude());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static SimulatedLocation middleLocation(@NonNull SimulatedLocation start
SimulatedLocation location = new SimulatedLocation(start);
location.setLatitude(toDegree(lat2));
location.setLongitude(toDegree(lon2));
location.setBearing(bearing);
location.setBearing(bearing, end.getLatitude(), end.getLongitude());
location.setTrafficLight(false);
return location;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private Location getDestinationLocation(@NonNull Location fromLocation) {

if (destLatLon != null) {
Location destLocation = new Location("", destLatLon.getLatitude(), destLatLon.getLongitude());
destLocation.setBearing(fromLocation.bearingTo(destLocation));
destLocation.setBearing(fromLocation.bearingTo(destLocation), destLatLon.getLatitude(), destLatLon.getLongitude());
return destLocation;
}

Expand Down