Mapbox-navigation-android: Footer informations are not correct for a long directions route

Created on 22 Oct 2018  路  2Comments  路  Source: mapbox/mapbox-navigation-android

Android API: 25 (Google Nexus 5), 27 (Samsung A6)
Mapbox Navigation SDK version: 0.20.0 & 0.21.0

Steps to trigger behavior

  1. Calculate a long route, e.g:
    Point origin = Point.fromLngLat( 10.684159, 53.874427);
    Point destination = Point.fromLngLat(15.819441, 38.017852);
    ... which gives the following route:
    2018-10-22 10 18 54

For completeness, the code:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.mapbox.api.directions.v5.DirectionsCriteria;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.services.android.navigation.ui.v5.NavigationLauncher;
import com.mapbox.services.android.navigation.ui.v5.NavigationLauncherOptions;
import com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute;
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute;

import java.util.Locale;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {

    private DirectionsRoute directionsRoute;
    private NavigationMapRoute navigationMapRoute;
    private MapView mapView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mapView = findViewById(R.id.mapView);
        mapView.onCreate(savedInstanceState);
        mapView.getMapAsync(mapboxMap -> {

            Point origin = Point.fromLngLat( 10.684159, 53.874427);
            Point destination = Point.fromLngLat(15.819441, 38.017852);

            NavigationRoute.builder(MainActivity.this)
                    .accessToken(Mapbox.getAccessToken())
                    .origin(origin)
                    .destination(destination)
                    .voiceUnits(DirectionsCriteria.METRIC)
                    .language(Locale.GERMAN)
                    .profile(DirectionsCriteria.PROFILE_DRIVING)
                    .build()
                    .getRoute(new Callback<DirectionsResponse>() {
                        @Override
                        public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
                            try {
                                directionsRoute = response.body().routes().get(0);

                                LatLngBounds latLngBounds = new LatLngBounds.Builder()
                                        .include(new LatLng(origin.latitude(), origin.longitude()))
                                        .include(new LatLng(destination.latitude(), destination.longitude()))
                                        .build();
                                mapboxMap.easeCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, 200), 5000);

                                if (directionsRoute != null) {
                                    /*ToastCompat.makeText(MainActivity.this, "hello", Toast.LENGTH_SHORT)
                                            .setBadTokenListener(toast -> {
                                                Timber.d("Bad Token");
                                            }).show();*/

                                    if (navigationMapRoute != null) {
                                        navigationMapRoute.removeRoute();
                                    } else {
                                        navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap);
                                    }
                                    navigationMapRoute.addRoute(directionsRoute);
                                    findViewById(R.id.fab).setVisibility(View.VISIBLE);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void onFailure(Call<DirectionsResponse> call, Throwable t) {
                        }
                    });

        });

        findViewById(R.id.fab).setOnClickListener(view -> {
            NavigationLauncherOptions.Builder optionsBuilder = NavigationLauncherOptions.builder()
                    .shouldSimulateRoute(false)
                    .directionsProfile(DirectionsCriteria.PROFILE_DRIVING);

            optionsBuilder.directionsRoute(directionsRoute);

            NavigationLauncher.startNavigation(MainActivity.this, optionsBuilder.build());
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        if (mapView != null) {
            mapView.onResume();
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (mapView != null) {
            mapView.onStart();
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        mapView.onStop();
    }

    @Override
    public void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mapView.onLowMemory();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:layout_gravity="bottom|end"
            android:baselineAlignBottom="true"
            android:visibility="gone"
            app:srcCompat="@drawable/ic_circle" />
    </RelativeLayout>

</android.support.constraint.ConstraintLayout>
  1. Start mapbox navigation ui

Expected behavior

Correct footer informations (duration, distance, arrival), like in v0.19.0:
2018-10-22 10 19 02

Actual behavior

2018-10-22 10 18 59

Most helpful comment

Hey @P-Zenker 馃憢 friendly reminder that 0.22.0 version of the SDK was released yesterday 馃帀

Thanks for bringing this to us!

All 2 comments

Hey @P-Zenker 馃憢 Thanks for reaching out and report your issue.

This is the same issue as https://github.com/mapbox/mapbox-navigation-android/issues/1404

FYI #1437 landed fixing OP and it'll be available in the next release 0.22.0 馃帀

In the meantime, you can test using the SNAPSHOT. Following you can find installation instructions for SNAPSHOTs:

repositories {
    jcenter()
    maven { url 'https://mapbox.bintray.com/mapbox' }
    maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
    // ...
}

dependencies {
    // ...
    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.22.0-SNAPSHOT'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.22.0-SNAPSHOT'
    // ...
}

Thanks a lot!

Closing as it'll be fixed in the next release.

Hey @P-Zenker 馃憢 friendly reminder that 0.22.0 version of the SDK was released yesterday 馃帀

Thanks for bringing this to us!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carstenhag picture carstenhag  路  5Comments

karussell picture karussell  路  4Comments

headbanggg picture headbanggg  路  5Comments

Guardiola31337 picture Guardiola31337  路  5Comments

trinhvanminh2009 picture trinhvanminh2009  路  5Comments