zoukankan      html  css  js  c++  java
  • android高德地图绘制线 渐变处理

    这个是为了实现淘宝物流轨迹的那种样式,轨迹路线是渐变色。

    先说下物流轨迹实现流程。

    1.高德地图3d、导航、搜索三个sdk的支持

    2.通过导航获取一条路径,这个路径包含的点相当多,可能有上万个。

    3.利用路径中的点划线,划线的点和导航提供的点是用的格式不一样,需要简单转换一下。

    4.使用android自带的api “ArgbEvaluator”来计算每个点的颜色值。

    5.把所有的颜色值放进一个数组,然后使用.colorValues(colorList).useGradient(true)这两个设置,就可以把线绘制出来了。

                @Override
                public void onCalculateRouteSuccess(int[] ints) {
                    if(ints!=null&&ints.length>0){
                        AMapNaviPath naviPath = mAMapNavi.getNaviPath();//导航返回的路径
    
                        if(naviPath.getCoordList()!=null){
                            ArgbEvaluator argbEvaluator = new ArgbEvaluator();//渐变色计算类
                            int colorStart = Color.parseColor("#FFA17A");
                            int colorEnd = Color.parseColor("#FF5934");
                            ArrayList<LatLng> pathPointList = new ArrayList<>();
                            List<Integer> colorList = new ArrayList<>();
                            int size = naviPath.getCoordList().size();//路径上所有的点
                            for (int i = 0; i <size; i++) {
                                NaviLatLng naviLatLng = naviPath.getCoordList().get(i);
                                LatLng latLng = new LatLng(naviLatLng.getLatitude(),naviLatLng.getLongitude());
                                int currentColor = (int) (argbEvaluator.evaluate((float) i/(float)size, colorStart, colorEnd));//计算每个点需要的颜色值
                                colorList.add(currentColor);
                                pathPointList.add(latLng);
                            }
    
                            PolylineOptions polylineOptions = new PolylineOptions()
                                    .width(DensityUtil.dip2px(4))
    //                                .color(Color.parseColor("#FF5934"))
                                    .colorValues(colorList)
                                    .useGradient(true)
                                    .addAll(pathPointList);
                            mMapControl.addPolyline(polylineOptions);
                        }
                    }
                }
  • 相关阅读:
    mac c++编译出现segmentation fault :11错误
    ssh 连接缓慢解决方法
    237. Delete Node in a Linked List
    203. Remove Linked List Elements
    Inversion of Control Containers and the Dependency Injection pattern
    82. Remove Duplicates from Sorted List II
    83. Remove Duplicates from Sorted List
    SxsTrace
    使用CCleaner卸载chrome
    decimal and double ToString problem
  • 原文地址:https://www.cnblogs.com/wangyuehome/p/12177524.html
Copyright © 2011-2022 走看看