【问题标题】:how to achieve car moving animation in MapMyIndia android SDK如何在 MapMyIndi​​a android SDK 中实现汽车移动动画
【发布时间】:2019-08-06 06:54:29
【问题描述】:

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

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

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

【问题讨论】:

  • 嗨,我是地图新手,我需要帮助初始化 MapboxMap 类。因为它需要设置addOnMapClickListener。

标签: android mapbox-android mapbox-marker mapmyindia-api


【解决方案1】:

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

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

这里是代码 sn-p 如果你想我可以发布整个逻辑

   // 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;
    }

【讨论】:

  • 谢谢,是的,它可以在谷歌地图中使用,即使我已经这样做了。但我需要 MapBox 他们被赋予标记旋转。没有旋转就不能完美的汽车移动动画。
  • 让我检查并告诉你
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-18
  • 1970-01-01
  • 2017-04-16
  • 2011-01-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多