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 @@ -17,8 +17,10 @@
import com.mapbox.services.Constants;
import com.mapbox.services.android.navigation.testapp.R;
import com.mapbox.services.android.navigation.v5.MapboxNavigation;
import com.mapbox.services.android.navigation.v5.RouteProgress;
import com.mapbox.services.android.navigation.v5.listeners.NavigationEventListener;
import com.mapbox.services.android.navigation.v5.listeners.OffRouteListener;
import com.mapbox.services.android.navigation.v5.listeners.ProgressChangeListener;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
import com.mapbox.services.api.directions.v5.models.DirectionsResponse;
Expand All @@ -37,7 +39,8 @@
import timber.log.Timber;

public class RerouteActivity extends AppCompatActivity implements OnMapReadyCallback, LocationEngineListener,
Callback<DirectionsResponse>, MapboxMap.OnMapClickListener, NavigationEventListener, OffRouteListener {
Callback<DirectionsResponse>, MapboxMap.OnMapClickListener, NavigationEventListener, OffRouteListener,
ProgressChangeListener {

@BindView(R.id.mapView)
MapView mapView;
Expand All @@ -63,6 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Initialize MapboxNavigation and add listeners
navigation = new MapboxNavigation(this, Mapbox.getAccessToken());
navigation.addNavigationEventListener(this);

}

@Override
Expand Down Expand Up @@ -100,6 +104,7 @@ public void onRunning(boolean running) {
this.running = running;
if (running) {
navigation.addOffRouteListener(this);
navigation.addProgressChangeListener(this);
}
}

Expand All @@ -111,6 +116,12 @@ public void userOffRoute(Location location) {
mapboxMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())));
}


@Override
public void onProgressChange(Location location, RouteProgress routeProgress) {
System.out.println(routeProgress.getCurrentLegProgress().getStepIndex());
}

@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
DirectionsRoute route = response.body().getRoutes().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void onLocationChanged(DirectionsRoute directionsRoute, Location location) {
previousRouteProgress = new RouteProgress(directionsRoute, location, 0, 0, NavigationConstants.NONE_ALERT_LEVEL);
}

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

Expand Down