首页 > 解决方案 > 如何删除折线中的行进部分并像 uber,swiggy 一样对其进行动画处理?

问题描述

我有一个疑问,但这可能会多次回答,但我找不到任何解决方案。我的疑问是如何像 uber 那样在折线上为标记设置动画现在让我详细解释一下,我经常从服务器上拉长,基于此我需要删除折线的行进部分并对其进行动画处理,现在让我发布我尝试过的内容远的。

这是我经常拉长的方法

public void UpdatePolyline(Double lat_decimal,Double lng_decimal){
           List<LatLng>removedline=new ArrayList<>();
            float distance=60.0f;
            if (polylineLatlng.size()>0){
            for (int i = 0; i < polylineLatlng.size(); i++) {
                if (polylineLatlng.size()>0) {
                    try {
                        float smallest_distance=CalculationByDistance(polylineLatlng.get(i),new LatLng(lat_decimal, lng_decimal));
                        if (smallest_distance<distance){
                            removedline.add(polylineLatlng.get(i));
                            polylineLatlng.remove(i);
                            distance=smallest_distance;
                        }
                }catch (Exception ex){
                    ex.printStackTrace();
                    break;
                    }
                }
                else {
                    break;
                }
            }
        }

        if (mpolyline != null) {
            if (polylineLatlng.size() > 0) {
               mpolyline.setPoints(polylineLatlng);
          for (int i=0;i<removedline.size();i++){
                Location location = new Location("");
                location.setLatitude(removedline.get(i).latitude);
                location.setLongitude(removedline.get(i).longitude);
                setDriverMarker(location);
            }

            }
            else {
                Location location = new Location("");
                location.setLatitude(lat_decimal);
                location.setLongitude(lng_decimal);
                setDriverMarker(location);
            }

        }}}



private void setDriverMarker(Location latLng) {
        if (latLng != null) {
            if (markerDriver == null) {
                RideMarker(latLng.getLatitude(),latLng.getLongitude());
            } else {
               move(markerDriver,latLng);

            }
        }}
    public  void move( final Marker marker, final Location toPosition) {
        if (fromPosition != null && marker != null && toPosition != null) {
            final Handler handlerRotation = new Handler();
            final long startAngle = SystemClock.uptimeMillis();
            final float startRotation = marker.getRotation();
            final long durationRotation = 300;
            final Interpolator interpolatorRotation = new LinearInterpolator();
            float bearing = fromPosition.bearingTo(toPosition);
            //     Print.e("Bearing:" + bearing);
            angle = bearing<0?(360+bearing):bearing;
            angle = angle%360f;
            //   Print.e("Angle:" + angle);
            handlerRotation.post(new Runnable() {
                @Override
                public void run() {
                    long elapsed = SystemClock.uptimeMillis() - startAngle;
                    float t = interpolatorRotation.getInterpolation((float) elapsed / durationRotation);
                    float rot = t * angle + (1 - t) * startRotation;
                    float mAngle = -rot > 180 ? rot / 2 : rot;
                    marker.setRotation(mAngle);

                    if (t < 1.0) {
                        handlerRotation.postDelayed(this, 16);
                    } else {
                        final Handler handler = new Handler();
                        final long start = SystemClock.uptimeMillis();
                        Projection projection = map.getProjection();
                        Point startPoint = projection.toScreenLocation(marker.getPosition());
                        final LatLng startLatLng = projection.fromScreenLocation(startPoint);
                        final long duration = 1000;
                        final Interpolator interpolator = new LinearInterpolator();
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                long elapsed = SystemClock.uptimeMillis() - start;
                                float t = interpolator.getInterpolation((float) elapsed
                                        / duration);
                                double lng = t * toPosition.getLongitude() + (1 - t)
                                        * startLatLng.longitude;
                                double lat = t * toPosition.getLatitude() + (1 - t)
                                        * startLatLng.latitude;
                                marker.setPosition(new LatLng(lat, lng));
                                map.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
                                        .target(new LatLng(toPosition.getLatitude(),toPosition.getLongitude()))
                                        .zoom(map.getCameraPosition().zoom)
                                        .build()));
                                if (t < 1.0) {
                                    // Post again 16ms later.
                                    handler.postDelayed(this, 16);
                                }
                            }
                        });
                    }
                }
            });
        }
        fromPosition = toPosition;
    }

但我无法在它上面设置动画标记,甚至折线的行进部分也没有删除如何做到这一点,请任何人分享这个我正在努力解决这个问题,谢谢!

标签: androidgoogle-maps-markerspolyline

解决方案


推荐阅读