I am attempting to implement a navigation component to my application following this MapBox guide:
https://docs.mapbox.com/help/tutorials/android-navigation-sdk/
When I attempt to call .startNavigation(...)
I get an unexpected error:
2020-03-08 19:51:45.786 11394-11394/com.example.mapboxnav A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8 in tid 11394 (mple.mapboxnav), pid 11394 (mple.mapboxnav)
Since the application I'm creating features many buttons, I've implemented View.OnClickListener
and am calling the Navigation interface when a user presses the navigation button (R.id.startNav
). However, as soon as a user presses the button the application crashes.
The currentRoute
is working and shown on the map upon calling getRoute
, like the example. I have verified that currentRoute
is definitely not null
. I have also attempted to start navigation with different coordinates without any luck.
currentRoute
contains a route from the user's current/last known location to a specified destination. For reference, the line is set/generated with the following method:
public void initLine(Double lng, Double lat) {
Location lastKnownLocation = mapboxMap.getLocationComponent().getLastKnownLocation();
Point origin = Point.fromLngLat(lastKnownLocation.getLongitude(), lastKnownLocation.getLatitude());
Point destination = Point.fromLngLat(lng, lat);
getRoute(origin, destination);
}
onClick:
public void onClick(View v) {
switch (v.getId()) {
...
case R.id.startNav:
boolean simulateRoute = true;
NavigationLauncherOptions options = NavigationLauncherOptions.builder()
.directionsRoute(currentRoute)
.shouldSimulateRoute(simulateRoute)
.build();
NavigationLauncher.startNavigation(MainActivity.this, options); // Causes Crash
}
}
I spend two and a half days over this until I discovered that the problem is that we need to set the location Engine before calling :
NavigationLauncher.startNavigation(MainActivity.this, options);
so your code should look like this and it should work:
NavigationLauncherOptions options = NavigationLauncherOptions.builder()
.directionsRoute(currentRoute)
.shouldSimulateRoute(simulateRoute)
.build();
// Just add these three lines
MapboxNavigation navigation = new MapboxNavigation(DriveActivity.this, getString(R.string. mapbox_access_token));
navigation.setLocationEngine(locationEngine); mapboxMap.getLocationComponent().setLocationComponentEnabled(true);
NavigationLauncher.startNavigation(MainActivity.this, options);
Let me know how it goes
Criss