Невозможно проверить, лежат ли координаты на дороге

Я пытаюсь добавить проверку в своем приложении, чтобы следовать предопределенной карте маршрута. Я использую метод isLocationOnPath, но он показывает мне тост «Пожалуйста, следуйте по маршруту», даже когда я следую по маршруту.

Ниже у меня есть мой код:

    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();
            }
        }
    }

person Usman    schedule 20.03.2017    source источник
comment
Не могли бы вы показать пример значений new LatLng(AppPreferences.getLatitude(mCurrentActivity),AppPreferences.getLongitude(mCurrentActivity)) и routePoints?   -  person antonio    schedule 20.03.2017
comment
routePoints = [широта/долгота: (32.51688,74.50946), широта/долгота: (32.51723,74.50999), широта/долгота: (32.51892,74.50786), широта/долгота: (32.51938,74.50729), широта/долгота: (32.51944, 74.50718), широта/долгота: (32.51963,74.50682), широта/долгота: (32.51986,74.50596)]   -  person Usman    schedule 20.03.2017
comment
новая широта (широта / долгота: (32,51674666666667,74,5096))   -  person Usman    schedule 20.03.2017
comment
PolyUtil.isLocationOnPath(new LatLng(32.51674666666667,74.5096), routePoints, true, 50) возвращает true   -  person antonio    schedule 20.03.2017
comment
я не понял твою мысль   -  person Usman    schedule 20.03.2017
comment
Используя указанные вами параметры, isLocationOnPath возвращает true, как и ожидалось, поэтому ваша проблема в другом. Вы должны попытаться изолировать свою проблему, чтобы решить ее   -  person antonio    schedule 20.03.2017
comment
После изменения режима движения на Cycle он некоторое время показывает мне тост, а затем исчезает, то же самое происходит постоянно.   -  person Usman    schedule 20.03.2017
comment
Что я думаю... Проверяется только первая точка списка RoutePoints   -  person Usman    schedule 20.03.2017
comment
Когда я удаляюсь на 50 метров от моей начальной точки, он показывает мне тост следования за местоположением.   -  person Usman    schedule 20.03.2017
comment
И каково значение new LatLng(AppPreferences.getLatitude(mCurrentActivity),AppPreferences.getLongitude(mCurrentActivity)), когда вы находитесь в 50 метрах от начальной точки?   -  person antonio    schedule 20.03.2017
comment
Эти значения обновляются до текущего местоположения   -  person Usman    schedule 20.03.2017
comment
Возможно, проблема заключается в значении вашего текущего местоположения, поскольку PolyUtil.isLocationOnPath — хорошо протестированная функция. Вы можете взглянуть на stackoverflow.com/questions/37136981/   -  person antonio    schedule 20.03.2017
comment
Не могли бы вы заменить проверку PolyUtil этим и рассказать нам, что содержится в всплывающем сообщении? if (!PolyUtil.isLocationOnPath(new LatLng(AppPreferences.getLatitude(mCurrentActivity),AppPreferences.getLongitude(mCurrentActivity)),routePoints,true,50)){ Toast.makeText(mCurrentActivity, +AppPreferences.getLatitude(mCurrentActivity)+AppPreferences.getLongitude (mCurrentActivity), Toast.LENGTH_SHORT).show(); }   -  person throws_exceptions_at_you    schedule 22.03.2017
comment
Теперь проблема в том, что когда я выбираю прямой путь, он работает нормально, а когда у меня нет прямого пути, он дает мне сообщение о следовании по пути.   -  person Usman    schedule 24.03.2017