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 ?

  • Take a look at [this](https://github.com/mapbox/mapbox-navigation-android/blob/master/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/WaypointNavigationActivity.java) repo. – Andrii Omelchenko Jan 24 '18 at 11:50

2 Answers2

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();
Dan Nesfeder
  • 298
  • 1
  • 6
  • 1
    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" } – Sushant Garg Apr 09 '19 at 07:32
  • 1
    @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. https://docs.mapbox.com/api/navigation/#directions – geografa Feb 06 '20 at 19:24
  • @SushantGarg thanks a lot! Your answer helped me :) For Android SDK, users have to use `DirectionsCriteria.DRIVING` in `profile` method – jashgopani Jul 11 '20 at 07:12
-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

Gowthaman M
  • 8,057
  • 8
  • 35
  • 54