问题
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