1

I've migrating Google map to MapMyIndia in our Android App(like Uber). All integration parts are done and map working fine, In Document i could not see cab moving animation part.

marker.setAnchor(0.5f, 0.5f);
marker.setRotation(getBearing(start, end));

For making cab animation,i thought above lines are required. But it's not available in Android SDK. Please assist how to achieve the cab animation (like Uber animation)

Gowsik Raja
  • 684
  • 1
  • 8
  • 22
  • Hi, I am new to map things, I need help with the initialization of MapboxMap class. because it needs to set addOnMapClickListener. – Karan Malhotra Feb 06 '21 at 04:05

1 Answers1

1

Here is how did it in google map I think this should work in your case as well ... or at least you will get idea

if you have all lat lng ... loop through the list with some delay and then apply animation to marker

here is code snippet if you want i can post whole logic

   // animate marker between two points to avoid jumpimg or shaking movement of marker while playing trip



   private void moveMarkerPlay(double lat, double lng, Marker marker, double latNew, double lngNew) {


        marker.setRotation((float) bearingBetweenLocations(new LatLng(lat, lng), new LatLng(latNew, lngNew)));

        animateMarkerToICS(marker, new LatLng(latNew, lngNew), new LatLngInterpolator.Spherical());
        if (playCount % (5 * playSpeed) == 0) {

            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latNew, lngNew), mMap.getCameraPosition().zoom));
        }


    }

    public static ObjectAnimator animator;

    public void animateMarkerToICS(Marker marker, LatLng finalPosition, final LatLngInterpolator latLngInterpolator) {
        TypeEvaluator<LatLng> typeEvaluator = (fraction, startValue, endValue) -> latLngInterpolator.interpolate(fraction, startValue, endValue);
        Property<Marker, LatLng> property = Property.of(Marker.class, LatLng.class, "position");

        animator = ObjectAnimator.ofObject(marker, property, typeEvaluator, finalPosition);
        animator.setDuration(330 / playSpeed);
        animator.start();
    }



 //Calculate bearing (angle) between two lat lng used for rotating marker as car moves
    private double bearingBetweenLocations(LatLng latLng1, LatLng latLng2) {

        double PI = 3.14159;
        double lat1 = latLng1.latitude * PI / 180;
        double long1 = latLng1.longitude * PI / 180;
        double lat2 = latLng2.latitude * PI / 180;
        double long2 = latLng2.longitude * PI / 180;

        double dLon = (long2 - long1);

        double y = Math.sin(dLon) * Math.cos(lat2);
        double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
                * Math.cos(lat2) * Math.cos(dLon);

        double brng = Math.atan2(y, x);

        brng = Math.toDegrees(brng);
        brng = (brng + 360) % 360;

        return brng;
    }
akshay_shahane
  • 4,423
  • 2
  • 17
  • 30
  • Thanks,Yes it will work in Google Map, even I've already done it. But i need MapBox they are given marker rotation. Without rotation it not perfect car moving animation right. – Gowsik Raja Aug 06 '19 at 07:19
  • 1
    have you checked this https://stackoverflow.com/questions/53517370/rotate-and-change-position-for-markers-in-latest-mapbox-sdk-6-7/54124090#54124090 – akshay_shahane Aug 06 '19 at 07:26
  • Let me check and let you know – Gowsik Raja Aug 06 '19 at 07:42