gpt4 book ai didi

android - 如何从数组列表中动态添加多段线

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:35:01 26 4
gpt4 key购买 nike

我有一个

places = ArrayList<ArrayList<LatLng>>

我正在将 LatLng 点添加到内部 ArrayList 中,然后我有一个循环并向 map 添加多段线的 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());
}

最佳答案

使用折线和数组列表在 map 中添加多个点

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);

关于android - 如何从数组列表中动态添加多段线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16311076/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com