2017-04-05 24 views
0

我正面臨一個真正的挑戰,我希望你們能幫我弄清楚。 我爲給定的位置對象創建了一條折線,而我想要做的是將一個自定義標記放置在原點中,並使其全部通過折線移動,而不一定要跟蹤位置,只需移動折線。Marker在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); 
相關問題