因此,要删除我添加的折线,我知道我需要调用polyline.remove()。问题在于它无法正常工作。
我已尝试设置以下代码,以确定是否可能是我的逻辑错误。
public class RouteFinder {
private GoogleMap _googleMap;
private Polyline _lastRoute;
...
public void displayRoute(String result) {
...
PolylineOptions line = new PolylineOptions();
line.color(Color.parseColor("#e5007d"));
line.width(3);
JSONObject startLocation = legs.getJSONObject("start_location");
line.add(new LatLng(startLocation.getDouble("lat"),startLocation.getDouble("lng")));
for(int i = 0; i < steps.length(); i++){
JSONObject step = steps.getJSONObject(i);
JSONObject end = step.getJSONObject("end_location");
line.add(new LatLng(end.getDouble("lat"),end.getDouble("lng")));
}
//Add line to map
_lastRoute = _googleMap.addPolyline(line);
_lastRoute.remove();
}
...
}
所以我在添加之后立即删除该行。但它仍然出现在地图上。我做错了什么?