1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

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

Discussion in 'Android Questions' started by jose luis gudino, Jun 3, 2019.

  1. jose luis gudino

    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

    Code:
    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();
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. jose luis gudino

    jose luis gudino Member Licensed User

    It works perfect!!!
    Thank
     
    Erel likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice