2017-05-31 1 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); 
関連する問題