我正在尝试添加检查我的应用程序以遵循预定义的路线图。我正在使用isLocationOnPath方法,但它显示我的Toast"请按照路线"即使我遵循这条路线。
下面我有我的代码:
private void StartCheckingForQuestionInRadius() {
if (visitedPoints == null) {
visitedPoints = new ArrayList<LatLng>();
}
try {
final Runnable r = new Runnable() {
public void run() {
if (handelrCheck) {
if (visitedPoints.size() != allQuestions.size() && QuestionOnTheRoute() < mCircle.getRadius() && !isDone() && Integer.parseInt(allQuestions.get(questionNumber).getSequence())==sequenceFlag) {
visitedPoints.add(new LatLng(Double.parseDouble(allQuestions.get(questionNumber).getLat()), Double.parseDouble(allQuestions.get(questionNumber).getLng())));
showPopup(); // show question pop up when it is inside user radius
//add viisited check point to menu
VisitedcheckPoint++;
sequenceFlag++;
heading5.add("" + VisitedcheckPoint);
for (int i = 0; i < heading5.size(); i++) {
if (heading5.size() > 1) {
heading5.remove(0);
}
}
}
else if (checkCompleteSurvey()<mCircle.getRadius()) { // when user complete survey
handelrCheck = false;
handlerForQuestions = null;
showAllAnswers(); // show all ansers to user when user complete survey
}
if (!PolyUtil.isLocationOnPath(new LatLng(AppPreferences.getLatitude(mCurrentActivity),AppPreferences.getLongitude(mCurrentActivity)),routePoints,true,50)){
Toast.makeText(mCurrentActivity, "Please follow the route", Toast.LENGTH_SHORT).show();
}
// else if (visitedPoints.size() == databaseHandler.getQuestionOnRoute().size()) { // when user complete survey
// handelrCheck = false;
// handlerForQuestions = null;
// showAllAnswers(); // show all ansers to user when user complete survey
//
// }
}
if (handlerForQuestions != null)
handlerForQuestions.postDelayed(this, pooltime);
}
};
handlerForQuestions.postDelayed(r, pooltime);
} catch (Exception e) {
e.printStackTrace();
}
}
我在事件中调用此方法如下:
@Subscribe
public void onEvent(String action) {
if (action.equalsIgnoreCase(PreferencesKeys.LOCATION_UPDATED)) {
firstTime = true;
firstTime = true;
myLocation = new LatLng(AppPreferences.getLatitude(mCurrentActivity), AppPreferences.getLongitude(mCurrentActivity));
if (mCircle != null) {
mCircle.remove();
}
drawMarkerWithCircle(myLocation);
if (firstTime) {
// animateCameraTo(AppPreferences.getLatitude(mCurrentActivity), AppPreferences.getLongitude(mCurrentActivity));
}
if (handelrCheck && handlerForQuestions == null) {
handlerForQuestions = new Handler();
StartCheckingForQuestionInRadius();
}
}
}