我正在使用Mapbox Android SDK如何獲得從當前位置到下一步的距離,方向和持續時間?
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:[email protected]')
。
我問過類似的問題之前在here,但仍然有一些問題。當我獲得currentRoute時,我不知道如何實現。我的代碼如下:
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()
將內onLocationChanged()
被調用。我認爲MapBox SDK應該將這些數據提供給開發人員,而不是由開發人員自己實施。或者如果我錯過了SDK中的重要信息?任何建議?
有什麼方便的方法可以知道我目前的Routestep?如果我可以得到我目前的Routestep,我可以通過在步驟列表中添加Routestep索引來找到我的下一個Routestep。在我得到下一個RouteStep後,我可以使用方法computeDistance()計算我的當前和RouteStep之間的距離。我認爲這個解決方案對於開發者來說很奇怪。爲什麼currentRoute不能返回這些值或向開發人員提供方法?我不知道如何實現這一點。沒有在他們的文件中找到。 – user3034559