I'm using Mapbox Android SDK
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:3.0.0@aar')
.
I asked the similar question before at here, but still have some problem. I don't know how to implement when I get currentRoute. my code is as below:
private Waypoint lastCorrectWayPoint;
private boolean checkOffRoute(Waypoint target) {
boolean isOffRoute = false;
if(currentRoute != null){
if (currentRoute.isOffRoute(target)) {
showMessage("You are off-route, recalculating...");
isOffRoute = true;
lastCorrectWayPoint = null;
//would recalculating route.
} else {
lastCorrectWayPoint = target;
String direction = "Turn right"; //The message what should I prompt to user
double distance = 0.0;//The distance which from target to next step.
int duration = 0;//The time which from target to next step.
String desc = "Turn right to xx street.";
//Implement logic to get them here.
showMessage("direction:" + direction + ", distance:" + distance + ", duration:" + duration + ", desc:" + desc);
}
}
checkOffRoute()
would be called within onLocationChanged()
. I think MapBox SDK should provide these data to developer instead of developer implement it by himself. or if I miss something important information in SDK? Any suggestion?
hope your app is coming along well. I see your trying to get direction, distance, and duration to next step. I'll try and answer this as best I can while keeping it short.
Direction
First when you request the route you need to include a couple lines:
Once you receive the response you can do something along the lines of
which will give you the approximate cardinal direction of travel following the maneuver. Typically one of the following: 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', or 'NW'. This specific line gives you the first route in the list (also typically the shortest and best choice route) and the first step. To change through the steps you simply change the integer value of the second
.get(int)
to whatever step you need.Duration and Distance
Same as above but instead of
.getDirection()
you use:and
respectively. I hope this at least helps to guide you in the right direction while creating your app.