2017-04-05 12 views
0

私は本当の挑戦に直面しています。 私は、指定されたPositionオブジェクトに対してポリラインを作成しています。これは、カスタムマーカーを原点に置いてポリライン全体を移動することです。位置を追跡する必要はなく、ポリライン上を移動するだけです。Mapboxのポリラインを使ってマーカーを移動する

私の最初のステップは、ObjectAnimationオブジェクトを作成し、それをあるマーカーから別のマーカーに移動させることでしたが、私はポリラインに沿って移動させることができません。

ありがとうございます。また、問題を明確にするために必要な情報がありましたら、毎回このトピックをご覧になっています。

+0

試してみてください[リンク](http://stackoverflow.com/questions/40526350/how-to-move-marker-along-polyline-using-google-map/40686476) – ADimaano

答えて

0

私たちは、あなたがオブジェクトのアニメーターを使用して正しいだexample for this

を持って、あなたはまた、位置を更新し続けるために、ハンドラを使用するようにする必要があります。この記事はあなたを助けることができるかどう

// 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); 
関連する問題