本文介绍了如何动态地从一个ArrayList中添加折线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个
地方=的ArrayList< ArrayList的<经纬度>>
我加入经纬度点到内部的ArrayList,然后我有一个for循环的循环,并增加了折线的地图..但它没有做到这一点?我如何动态地添加折线的GoogleMap的?我检查是否地方正在填充,它是。
在此先感谢。
的ArrayList<折线> PL =新的ArrayList<折线>();
的for(int i = 0; I< places.size();我++){
pl.add(mMap.addPolyline(新PolylineOptions()的addAll(places.get(ⅰ))));
Log.e(场所大小,场所尺寸是+ places.size());
}
解决方案
一旦你有纬度的列表在列表中的经度,你可以使用下面画线。
名单,其中,经纬度>点=去$ C $℃聚(_path); //经纬度名单
的for(int i = 0; I< points.size() - 1;我++){
经纬度的src = points.get(ⅰ);
经纬度DEST = points.get第(i + 1);
// MMAP是Map对象
折线行= mMap.addPolyline(
新PolylineOptions()。增加(
新的经纬度(src.latitude,src.longitude)
新的经纬度(dest.latitude,dest.longitude)
).WIDTH(2)。颜色(Color.BLUE).geodesic(真)
);
}
以上在我的应用程序为我工作。
I have an
places = ArrayList<ArrayList<LatLng>>
I am adding LatLng points into the inner ArrayList and then I have a for loop that loops and adds polylines to the map.. except it doesnt do that...How can I add polylines dynamically to the GoogleMap? I checked whether or not places was being populated and it is.
Thanks in advance.
ArrayList<Polyline> pl = new ArrayList<Polyline>();
for(int i =0; i<places.size(); i++){
pl.add(mMap.addPolyline(new PolylineOptions().addAll(places.get(i))));
Log.e("size of places", "size of places is " + places.size());
}
解决方案
Once you have list of latitude an longitudes in your List, you can use the below to draw lines.
List<LatLng> points = decodePoly(_path); // list of latlng
for (int i = 0; i < points.size() - 1; i++) {
LatLng src = points.get(i);
LatLng dest = points.get(i + 1);
// mMap is the Map Object
Polyline line = mMap.addPolyline(
new PolylineOptions().add(
new LatLng(src.latitude, src.longitude),
new LatLng(dest.latitude,dest.longitude)
).width(2).color(Color.BLUE).geodesic(true)
);
}
the above worked for me in my application
这篇关于如何动态地从一个ArrayList中添加折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!