Search code examples
androidandroid-studionavigationmapboxmapbox-android

Cannot resolve method addWaypoint(com.mapbox.geojson.Point)


I'm trying to put some waypoints on the Navigation UI but I have the issue of the title, here's my code, in the foreach is where I have the problem. It seems like I didn't import something

Point[] waypoints = {Point.fromLngLat(2.444740599999932, 41.5381124),Point.fromLngLat(2.407215469098446, 41.520481047202615};

      @Override
public void onNavigationReady() {
    NavigationViewOptions.Builder options = NavigationViewOptions.builder();
    options.navigationListener(this);
    options.origin(origin);
    options.destination(destination);
    options.shouldSimulateRoute(true);
    options.progressChangeListener(this);

    for (Point waypoint : waypoints) {
        options.addWaypoint(waypoint);
    }

    navigationView.startNavigation(options.build());
}

Solution

  • addWayPoint is a method from NavigationRoute.Builder not NavigationViewOptions.Builder. That why the IDE cannot resolve it.

    From your code I guess you want to draw or simulate a navigation route (origin, destination, all points on route, etc..).

    Please take a look examples at below official site how to use NavigationRoute.Builder API.

    https://www.mapbox.com/help/android-navigation-sdk/