从地图中删除折线

时间:2017-04-04 11:17:27

标签: java android google-maps polyline

我试图在创建折线之前删除之前创建的折线,这就是我所拥有的:

    protected void fazerCaminho(ArrayList<HashMap<String, String>> listaPolylines) {
    if (line == null) {
        for (Map polyline : listaPolylines) {
            List<LatLng> decodedPath = PolyUtil.decode((String) polyline.get("points"));
            line = mMap.addPolyline(new PolylineOptions()
                    .width(3)
                    .color(Color.rgb(25, 151, 152))
                    .geodesic(true)
                    .addAll(decodedPath));
        }

    } else {
        line.remove();
        for (Map polyline : listaPolylines) {
            List<LatLng> decodedPath = PolyUtil.decode((String) polyline.get("points"));
            line = mMap.addPolyline(new PolylineOptions()
                    .width(3)
                    .color(Color.rgb(25, 151, 152))
                    .geodesic(true)
                    .addAll(decodedPath));
        }
    }
}

line.remove不起作用,这个解决方案适用于以前的版本但当时我没有for方法,我做错了什么?

1 个答案:

答案 0 :(得分:0)

创建List以存储您的Polyline并在添加新的private List<Polyline> lines = new ArrayList<>(); // ... private void removeLines() { for (Polyline line : lines) { line.remove(); } lines.clear(); } // ... protected void fazerCaminho(ArrayList<HashMap<String, String>> listaPolylines) { removeLines(); for (Map polyline : listaPolylines) { List<LatLng> decodedPath = PolyUtil.decode((String) polyline.get("points")); lines.add(mMap.addPolyline(new PolylineOptions() .width(3) .color(Color.rgb(25, 151, 152)) .geodesic(true) .addAll(decodedPath))); } } 之前清除它们:

select * from performance_schema.table_io_waits_summary_by_index_usage
where object_schema = 'your_schema'