如何移除折线中的行进部分并对其进行动画处理,如超级,浮雕?

时间:2018-10-20 10:31:06

标签: android google-maps-markers polyline

我有一个疑问,但这可能会回答很多次,但是我找不到关于此的任何解决方案。我的疑问是像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;
    }

但是我无法在其上设置标记动画,甚至折线的行进部分也无法消除该操作,请任何人分享这点,感谢前进的努力!

0 个答案:

没有答案