Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private Location mockLocation(Position position) {
lastLocation.setBearing((float) bearing);
}

lastLocation.setAccuracy(40f);
lastLocation.setAccuracy(3f);
lastLocation.setTime(SystemClock.elapsedRealtime());

return lastLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


import android.location.Location;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.mapbox.services.android.navigation.v5.listeners.AlertLevelChangeListener;
import com.mapbox.services.android.navigation.v5.listeners.OffRouteListener;
Expand All @@ -26,7 +28,6 @@ class NavigationEngine {

// Navigation state information
private RouteProgress previousRouteProgress;
private DirectionsRoute directionsRoute;
private MapboxNavigationOptions options;
private long timeIntervalSinceLastOffRoute;
private Location previousLocation;
Expand All @@ -41,7 +42,7 @@ class NavigationEngine {
* @param isSnapEnabled boolean true if the snapping to route features enabled, otherwise false
* @since 0.2.0
*/
NavigationEngine(MapboxNavigationOptions options, boolean isSnapEnabled) {
NavigationEngine(@NonNull MapboxNavigationOptions options, boolean isSnapEnabled) {
this.isSnapEnabled = isSnapEnabled;
this.options = options;
stepIndex = 0;
Expand All @@ -57,12 +58,15 @@ class NavigationEngine {
* @since 0.2.0
*/
void onLocationChanged(DirectionsRoute directionsRoute, Location location) {
this.directionsRoute = directionsRoute;
// if the previousRouteProgress is null, the route has just begun and one needs to be created
if (previousRouteProgress == null) {
previousRouteProgress = new RouteProgress(directionsRoute, location, 0, 0, NavigationConstants.NONE_ALERT_LEVEL);
}

if (TextUtils.equals(directionsRoute.getGeometry(), previousRouteProgress.getRoute().getGeometry())) {
resetRouteProgress();
}

// If the locations the same as previous, no need to recalculate things
if (location.equals(previousLocation)) {
return;
Expand Down Expand Up @@ -130,6 +134,11 @@ private void notifyProgressChange(Location location, RouteProgress routeProgress
}
}

void resetRouteProgress() {
legIndex = 0;
stepIndex = 0;
}

public boolean isSnapEnabled() {
return isSnapEnabled;
}
Expand Down Expand Up @@ -157,5 +166,4 @@ void setProgressChangeListeners(CopyOnWriteArrayList<ProgressChangeListener> pro
void setOffRouteListeners(CopyOnWriteArrayList<OffRouteListener> offRouteListeners) {
this.offRouteListeners = offRouteListeners;
}

}