mapbox-navigation-android add waypoints

怎甘沉沦 提交于 2019-12-14 02:59:51

问题


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:


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();



回答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



来源:https://stackoverflow.com/questions/48419893/mapbox-navigation-android-add-waypoints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!