2017-05-31 69 views
-1

我試圖在將地圖放置在地圖上之後更改折線,但它的點列表似乎是不可更改的。多義線點列表上的CRUD操作不起作用。更改折線點

PolylineOptions polylineOptions = new PolylineOptions() //New PolylineOptions 
    .add(new LatLng(FromNode.Lat, FromNode.Lon))   //with 2 coordinates 
    .add(new LatLng(ToNode.Lat, ToNode.Lon)); 
Polyline polyPath = map.addPolyline(polylineOptions);  //Add polyline on map 
polyPath.getPoints().remove(0);       //Should remove 0 element 
polyPath.getPoints().size();        //Still 2 elements 
polyPath.getPoints().add(new LatLng(0,0));    //Add new point 
polyPath.getPoints().size();        //Still 2 elements 

回答

0
Polyline.getPoints(); 

創建的點列表的副本,它不是點的實際列表的引用。 要設置新的點列表,需要獲取初始點列表,將其更改並設置爲折線。

List<LatLng> pointsList = Polyline.getPoints(); 
pointsList.remove(1); 
pointsList.set(0, new LatLng(1,1)); 
pointsList.add(new LatLng(0,0)); 
Polyline.setPoints(pointsList);