1

我已经在我们的 Android 应用程序(如 Uber)中将 Google 地图迁移到MapMyIndi​​a 。所有集成部分都已完成并且地图工作正常,在文档中我看不到驾驶室移动动画部分。

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

为了制作驾驶室动画,我认为上面的行是必需的。但它在 Android SDK 中不可用。请协助如何实现出租车动画(如优步动画

4

1 回答 1

1

这是在谷歌地图中是如何做到的我认为这也应该适用于你的情况......或者至少你会明白

如果你有所有 lat lng ... 循环遍历列表并有一些延迟,然后将动画应用于标记

这是代码片段,如果您愿意,我可以发布整个逻辑

   // 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;
    }
于 2019-08-06T07:01:44.593 回答