Drawing multi color PolyLines on Maps V2

╄→гoц情女王★ 提交于 2019-11-30 05:17:33

I just find a way to do that with OptionsLines, in fact, two OptionsLines. I use this function with a gpx file, that's why there ly personnal object TRKPT.

 int size = listPoints.size();
        PolylineOptions optline = new PolylineOptions();
        PolylineOptions optline2 = new PolylineOptions();
        optline.geodesic(true);
        optline.width(10);
        optline2.geodesic(true);
        optline2.width(10);
        for (int i = 0; i < size - 1; i++) {

            TRKPT pointD = listPoints.get(i);
            TRKPT pointA = listPoints.get(i + 1);
            int green = (int) ((float) 255 - (float) (i / (float) size) * (float) 255);
            int red = (int) ((float) 0 + (float) (i / (float) size) * (float) 255);

            optline.add(new LatLng(pointD.getLat(), pointD.getLon()), new LatLng(pointA.getLat(), pointA.getLon()));
            optline2.add(new LatLng(pointD.getLat(), pointD.getLon()), new LatLng(pointA.getLat(), pointA.getLon()));

            if(i%2 == 0){
                optline.color(Color.rgb(red, green, 0));
                mMap.addPolyline(optline);
                optline = new PolylineOptions();
                optline.geodesic(true);
                optline.width(10);
            }
            else{
                optline2.color(Color.rgb(red, green, 0));
                mMap.addPolyline(optline2);
                optline2 = new PolylineOptions();
                optline2.geodesic(true);
                optline2.width(10);
            }
        }

Now you have a beautiful line with gradient from green to red.

You can render anything you wish to a Bitmap and use GroundOverlay or TileOverlay with it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!