0

I search to add waypoints to my journey.

https://github.com/mapbox/mapbox-navigation-android/blob/master/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/WaypointNavigationActivity.java

In this example, the next waypoint is add at the end of the journey. I would like to add all points in the same journey. Have you an idea ?

1
  • Take a look at this repo. Commented Jan 24, 2018 at 11:50

2 Answers 2

2

You can add waypoints when making a new route request with NavigationRoute.

In our docs https://www.mapbox.com/android-docs/navigation/overview/, look under section 4. Requesting a route and you'll find an example of how to do this.

NavigationRoute.Builder builder = NavigationRoute.builder()
  .accessToken(Mapbox.getAccessToken())
  .origin(origin)
  .destination(destination);

for (Position waypoint : waypoints) {
  builder.addWaypoint(waypoint);
}

builder.build();
Sign up to request clarification or add additional context in comments.

3 Comments

It takes only one waypoint through this method, this is the output with 2 waypoints { "message": "Too many coordinates; maximum number of coordinates is 3.", "code": "InvalidInput" }
@SushantGarg this is likely because you are using the driving-traffic profile (3 waypoints max). You can switch to the driving profile for up to 25 waypoints. docs.mapbox.com/api/navigation/#directions
@SushantGarg thanks a lot! Your answer helped me :) For Android SDK, users have to use DirectionsCriteria.DRIVING in profile method
-2

Try this...Using google map

       StringBuilder sb_latlangdrive = new StringBuilder();
           for (int i = 0; i < arrayList.size(); i++) {
                String split[] = arrayList.get(i).split(",");
                sb_latlangdrive.append(split[0] + "," + split[1] + "|");
             }
             String split[] = arrayList.get(0).split(",");
             String split_endlocaiton[] = arrayList.get(arrayList.size() - 1).split(",");
             Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/dir/?api=1&origin=" + split[0] + "," + split[1] + "&destination=" + split_endlocaiton[0] + "," + split_endlocaiton[1] + "&waypoints=" + sb_latlangdrive.toString() + "&travelmode=driving");
             Intent intent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
             intent.setPackage("com.google.android.apps.maps");
             try {
                   startActivity(intent);
             } catch (ActivityNotFoundException ex) {
               try {
                     Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                     startActivity(unrestrictedIntent);
                   } catch (ActivityNotFoundException innerEx) {
                      Toast.makeText(TrackingTesting.this, "Please install a maps application", Toast.LENGTH_LONG).show();
                 }
             }

For reference see doc here

2 Comments

Ok but i would like to use MapBox Android in navigation mode.
@Gowthaman, Thanks for your efforts to help here, But This is a very un-related answer to the question, the question is about Mapbox.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.