如何动态地从一个ArrayList中添加折线折线、动态、ArrayList

由网友(三千繁華、虛夢壹場)分享简介:我有一个地方=的ArrayList< ArrayList的<经纬度>>我加入经纬度点到内部的ArrayList,然后我有一个for循环的循环,并增加了折线的地图..但它没有做到这一点?我如何动态地添加折线的GoogleMap的?我检查是否地方正在填充,它是。在此先感谢。的ArrayList&L...

我有一个

 地方=的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(真)
  );
}
 
数据结构 动态数组 ArrayList

以上在我的应用程序为我工作。

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

阅读全文

相关推荐

最新文章