[英]How to dynamically add polylines from an arraylist
我有一個
places = ArrayList<ArrayList<LatLng>>
我將LatLng點添加到內部ArrayList中,然后我有一個for循環,循環並向地圖添加折線......除了它不這樣做...如何動態地將折線添加到GoogleMap? 我檢查了地方是否正在填充,它是。
提前致謝。
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());
}
使用折線和arraylist在地圖中添加多個點
ArrayList<LatLng> coordList = new ArrayList<LatLng>();
// Adding points to ArrayList
coordList.add(new LatLng(0, 0);
coordList.add(new LatLng(1, 1);
coordList.add(new LatLng(2, 2);
// etc...
// Find map fragment. This line work only with support library
GoogleMap gMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
PolylineOptions polylineOptions = new PolylineOptions();
// Create polyline options with existing LatLng ArrayList
polylineOptions.addAll(coordList);
polylineOptions
.width(5)
.color(Color.RED);
// Adding multiple points in map using polyline and arraylist
gMap.addPolyline(polylineOptions);
一旦列表中有經度緯度列表,就可以使用下面的線條繪制線條。
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)
);
}
以上在我的申請中為我工作
您擁有的places
變量是什么,因為地點需要是該行中的所有位置而不僅僅是1個點。
假設places是ArrayList<LatLng>
那么通過執行places.get(i)
你只給出一個點,而不是整個點列表;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.