I am trying to add a Check in my app to follow predefined route map.I am using isLocationOnPath method but its showing me Toast of "Please follow route" even when I am following the route.
Below I have my code:
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();
}
}
I am calling this method in the Event as below:
@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();
}
}
}