Android Question [Solved]"smoothing" the movement of the Google map marker

jose luis gudino

Member
Licensed User
hI
I would like to "smoothing" the movement of the Google map marker,
I got the ValueAnimator function, which allows me to do that but I do not know how I can do it to integrate it into my B4A code

B4X:
  public void run(List<LatLng> polyLineList) {
      if (index < (polyLineList.size() - 1)) {
                index++;
                next = index + 1;
            } else {
                index = -1;
                next = 1;
               // stopRepeatingTask();
                return;
            }
        
        if (index < (polyLineList.size() - 1)) {
           //startPosition = polyLineList.get(index);
           startPosition = carMarker.getPosition();
           endPosition = polyLineList.get(next);
            }
           ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
            valueAnimator.setDuration(3000);
            valueAnimator.setInterpolator(new LinearInterpolator());
            valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {

                    v = valueAnimator.getAnimatedFraction();
                    lng = v * endPosition.longitude + (1 - v)
                            * startPosition.longitude;
                    lat = v * endPosition.latitude + (1 - v)
                            * startPosition.latitude;
                    LatLng newPos = new LatLng(lat, lng);
                    carMarker.setPosition(newPos);
                    carMarker.setAnchor(0.5f, 0.5f);
                    carMarker.setRotation(getBearing(startPosition, newPos));
                    googleMap.moveCamera(CameraUpdateFactory
                            .newCameraPosition
                                    (new CameraPosition.Builder()
                                            .target(newPos)
                                            .zoom(15.5f)
                                            .build()));


                }
            });         
          valueAnimator.start();
 
Top