[英]how to draw line (route) in android google map acoording to passed coordinates
Good coding to everyone, 对所有人的编码很好,
My situation is this; 我的情况是这样;
for example i have coordinates, lets say they are Q,W,E,R,T,Y,U. 例如我有坐标,可以说它们是Q,W,E,R,T,Y,U。
I want show this route in google map with PolylineOptions. 我想使用PolylineOptions在Google地图中显示此路线。 It's ok but how can i show passed coordinates on real time.
可以,但是如何实时显示传递的坐标。
For instance; 例如; QWERTYU is the route and showing with blue line.
QWERTYU是路线并用蓝线显示。 When I come the "R" ;QWE must be shown with grey(different) line.
当我来时,“ R”; QWE必须显示为灰色(不同)线。 And this must be real time.
这必须是实时的。
Any ideas? 有任何想法吗?
Using PolylineOptions you can achieve that. 使用PolylineOptions可以实现这一点。
First save the color's in XML file color.xml
首先将颜色保存在XML文件
color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
<color name="yellow">#FFFF00</color>
<color name="green">#00FF00</color>
<color name="cyan">#00FFFF</color>
<color name="blue">#0000FF</color>
<color name="magenta">#FF00FF</color>
<array name="colors">
<item>@color/red</item>
<item>@color/yellow</item>
<item>@color/green</item>
<item>@color/cyan</item>
<item>@color/blue</item>
<item>@color/magenta</item>
</array>
</resources>
Create a Latlong object of Q,W,E,R,T,Y,U and save it into a List
then pass it into a PolylineOptions like this. 创建一个Q,W,E,R,T,Y,U的Latlong对象,并将其保存到
List
然后将其传递给PolylineOptions这样。
int[] polyColor= context.getResources().getIntArray(R.array.colors);
for (int i = 0; i < list.size(); i++) {
LatLng latPoint = list.get(i);
googleMap.addPolyline(new PolylineOptions()
.add(latPoint)
.width(5)
.color(polyColor[i]));
}
make sure you have more colors than latlong :) 确保您的颜色比latlong还多:)
After lat of searching, i recognized this methodology. 经过一番搜寻,我意识到了这种方法。 I dont like , but it works.
我不喜欢,但是可以。 Everytime (current coordinate changed), i recall my metot.
每次(当前坐标改变),我都想起了我的小号。
The metot is above; 陨石在上面;
public void add(GoogleMap mGoogleMap) {
PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
for (int z = 0; z < list.size(); z++) {
LatLng point = list.get(z);
options.add(point);
}
mGoogleMap.addPolyline(options);
}
Everytime, somewhere in code i added LatLng to Arraylist (in code list) and recall this method. 每次,我在代码中的某个地方将LatLng添加到Arraylist(在代码列表中),然后调用此方法。 And this will be real time tracking.
这将是实时跟踪。 Any other specifications can be done now.
现在可以完成任何其他规格。
But i dont like this logic, if there will be any other solutions, please write. 但是我不喜欢这种逻辑,如果还有其他解决方案,请写。
=) =)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.