0

I am trying to implement track activity in my app and am stack on how to move a bike smoothly along polyline. I have created a service in driver app that periodically update firebase db with current location. On the customer app have create a TrackActivity that is supposed to read real time database change and move the car smoothly along polyline and this is where am stuck. This is what have done so far. What do I need to change this sample code

This is the method got from some link to animate bike but I dont know where to get the start and end latlong

 private void startAnimation(final LatLng startPosition, final LatLng endPosition) {

        final ValueAnimator valueAnimator = ValueAnimator.ofFloat(new float[] { 0.0F, 1.0F });
        valueAnimator.setDuration(3000L);
        valueAnimator.setInterpolator((TimeInterpolator)new LinearInterpolator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator param1ValueAnimator) {
                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);
                carMaker.setPosition(newPos);
                carMaker.setAnchor(0.5f, 0.5f);
                carMaker.setRotation(PolyLineUtil.getBearing(startPosition,newPos));
                mMap.moveCamera(CameraUpdateFactory.newCameraPosition(
                        new CameraPosition.Builder()
                                .target(newPos)
                                .zoom(15.5f)
                                .build()));
            }
        });
        valueAnimator.start();
    }

0 Answers0