Маркер перемещается по полилинии в Mapbox

Я столкнулся с реальной проблемой, и я надеюсь, что вы, ребята, поможете мне разобраться. Я создаю полилинию для заданных объектов Position, и я хотел бы поместить пользовательский маркер в начало координат и заставить его двигаться по всей полилинии, не обязательно отслеживая положение, просто перемещаясь по полилинии.

Моим первым шагом было создание объекта ObjectAnimation и перемещение его по линии от одного маркера к другому, но я не понимаю, как заставить его двигаться вдоль полилинии, а не по линии.

Заранее спасибо, и любая дополнительная информация, необходимая вам для прояснения проблемы, я просматриваю эту тему каждый раз!


person Nandoff    schedule 05.04.2017    source источник
comment
Попробуйте, может ли этот пост помочь вам link   -  person ADimaano    schedule 05.04.2017


Ответы (1)


У нас есть пример для этого

вы правы в использовании аниматора объектов, вам также нужно использовать обработчик, чтобы постоянно обновлять позицию.

// Animating the marker requires the use of both the ValueAnimator and a handler.
    // The ValueAnimator is used to move the marker between the GeoJSON points, this is
    // done linearly. The handler is used to move the marker along the GeoJSON points.
    handler = new Handler();
    runnable = new Runnable() {
      @Override
      public void run() {

        // Check if we are at the end of the points list, if so we want to stop using
        // the handler.
        if ((points.size() - 1) > count) {

          // Calculating the distance is done between the current point and next.
          // This gives us the duration we will need to execute the ValueAnimator.
          // Multiplying by ten is done to slow down the marker speed. Adjusting
          // this value will result in the marker traversing faster or slower along
          // the line
          distance = (long) marker.getPosition().distanceTo(points.get(count)) * 10;

          // animate the marker from it's current position to the next point in the
          // points list.
          ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
              new LatLngEvaluator(), marker.getPosition(), points.get(count));
          markerAnimator.setDuration(distance);
          markerAnimator.setInterpolator(new LinearInterpolator());
          markerAnimator.start();

          // This line will make sure the marker appears when it is being animated
          // and starts outside the current user view. Without this, the user must
          // intentionally execute a gesture before the view marker reappears on
          // the map.
          map.getMarkerViewManager().update();

          // Keeping the current point count we are on.
          count++;

          // Once we finish we need to repeat the entire process by executing the
          // handler again once the ValueAnimator is finished.
          handler.postDelayed(this, distance);
        }
      }
    };
    handler.post(runnable);
person cammace    schedule 05.04.2017