借鉴地图V2多色折线 [英] Drawing multi color PolyLines on Maps V2

查看:172
本文介绍了借鉴地图V2多色折线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我画我的地图上素色折线以下方式,和它的伟大工程:

I am drawing a plain color PolyLine on my map the following way, and it works great:

PolylineOptions polyLine = new PolylineOptions();  
polyLine.width(5);  
polyLine.color(Color.RED);  
polyLine.geodesic(true);  
for (int i = 0; i < speed.length; i++) {  
    polyLine.add(new LatLng(lat, lng));
}

map.addPolyline(polyLine);

现在我要画的不同点之间不同颜色的折线,这取决于这两个点之间的速度。

Now I would want to draw a polyline with different colors between different points, depending on the speed between those two points.

似乎有没有成为这样做的一个简单的方法。

There doesn't seem to be an easy way of doing it.

我指的是这样一个问题:绘制折线与不同颜色的V2地图,我可以添加多个 PolylineOptions 一个又一个,但我不认为这将是一个有效的方法,因为我在一个简单的数据集来绘制有2000多点。

I am referring to this question : draw polylines with different colors on v2 maps , and I can add multiple PolylineOptions one after another, but I don't think that will be an efficient approach, given I have more than 2000 points in a simple data set to draw.

有没有更好的做法?

理想的实现将是怎样的Nike +应用程序绘制线条图:

The ideal implementation would be how Nike+ app draws lines on maps:

将大大AP preciate任何帮助。

Would greatly appreciate any help.

在此先感谢!

推荐答案

我刚找到一个方法来做到这一点与OptionsLines,其实2 OptionsLines。 我用这个函数与GPX文件,这就是为什么有LY的personnal对象TRKPT。

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.

这篇关于借鉴地图V2多色折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆