Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Android

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Animate marker to new location whenever driver location (lat lng) changes on the server

here I am getting the driver's location from server. I need to pass the driver lat lnt to the loop and animate the marker accordingly. I tried to pass it directly to the startpostion and endpostion. But the marker flickers continuesly.

when I pass the driver's lat lng directly to the startposition and endposition the marker moves to the new location but it comes back if it does not get new lat lat from the server and also flickers continuously.


private void GetDriverloc(HashMap<String, String> map) {
   Call<DriverLocationResToCus> call = apiInterface.GetDriverLoc(map);
   System.out.println("enter the currency alert api" + call.request().url());
   call.enqueue(new Callback<DriverLocationResToCus>() {
       @Override
       public void onResponse(Call<DriverLocationResToCus> call, Response<DriverLocationResToCus> response) {


           if (response.isSuccessful()) {

               assert response.body() != null;
               DriverStartLat = response.body().getDriverCurrentLatStart();
               DriverStartLng = response.body().getDriverCurrentLngStart();
               DriverEndLat = response.body().getDriverCurrentLatEnd();
               DriverEndLng = response.body().getDriverCurrentLngEnd();

Utilities.printV("DriverStartLat", DriverStartLat);

               ValueAnimator polylineAnimator = ValueAnimator.ofInt(0, 100);
               polylineAnimator.setDuration(2000);
               polylineAnimator.setInterpolator(new LinearInterpolator());
               polylineAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                   @Override
                   public void onAnimationUpdate(ValueAnimator valueAnimator) {
                       List<LatLng> points = greyPolyLine.getPoints();
                       int percentValue = (int) valueAnimator.getAnimatedValue();
                       int size = points.size();
                       int newPoints = (int) (size * (percentValue / 100.0f));
                       List<LatLng> p = points.subList(0, newPoints);
                       blackPolyline.setPoints(p);
                   }
               });
               polylineAnimator.start();



                   mHandler = new Handler();
                   index = -1;
                   next = 1;
                   mHandler.postDelayed(new Runnable() {
                       @Override
                       public void run() {

                       if (index < points.size() - 1) {
                           index++;
                           next = index + 1;
                       }
                       if (index < points.size() - 1) {
                           startPosition = points.get(index);
                           endPosition = points.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);
                                   marker.setPosition(newPos);
                                   marker.setAnchor(0.5f, 0.5f);
                                   marker.setRotation(getBearing(startPosition, newPos));
                       mMap.moveCamera(CameraUpdateFactory
                               .newCameraPosition
                                       (new CameraPosition.Builder()
                                               .target(newPos)
                                               .zoom(15.5f)
                                               .build()));
                               }
                           });
                           valueAnimator.start();
                           mHandler.postDelayed(this, 3000);
                       }
                   }, 3000);

               Utilities.printV("DriverLocationResToCus", "DriverLocationResToCus SUCCESS");


           } else {

               Utilities.printV("DriverLocationResToCus", "DriverLocationResToCus FAILURE");

}
       }

       @Override
       public void onFailure(Call<DriverLocationResToCus> call, Throwable t) {

       }
   });

}


stackoverflow

Can anyone help me with this?
 
Marshal
Posts: 77539
372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't know any Android myself, but thank you for informing us of the double posting; please also inform them on SO. You would find it easier to get more attention if you give your thread a more informative title and give us more explanation of the problem.
 
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic