구글 지도에 Polyline을 통해 현재 이동하고 있는 경로를 구현하고 있습니다.
이동경로를 잘 표시하고 다른 기타 기능들도 모두 되는데 한가지 문제가 발생했는데요
경로를 지우는 것에서 문제가 생겼습니다.
각설하고 코드로 보여드리겠습니다.
private GoogleMap map;
private PolylineOptions polylineOptions;
private Polyline polyline;
private LocationManager locationManager;
private myLocation mylocation = new myLocation();
private Button btn_clear, btn_start;
private ArrayList<LatLng> testArray = new ArrayList<LatLng>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
btn_start = (Button) findViewById(R.id.btn_start);
btn_start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,mylocation);
return;
}
});
btn_clear = (Button) findViewById(R.id.btn_clear);
btn_clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
polyline.remove();
map.clear();
locationManager.removeUpdates(mylocation);
Intent intent = new Intent(TEST.this, WalkResult.class);
startActivity(intent);
}
});
polylineOptions = new PolylineOptions();
}
public class myLocation implements LocationListener {
@Override
public void onLocationChanged(Location location) {
LatLng spot = new LatLng(location.getLatitude(), location.getLongitude());
testArray.add(spot);
polyline = map.addPolyline(polylineOptions
.add(testArray.get(0))
.color(Color.DKGRAY));
Log.d("Insult", "testArray : " + testArray.get(0));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(spot, 17));
map.addPolyline(polylineOptions);
testArray.remove(0);
}
이런 코드인데요. 구글에 검색했을 때 경로를 지울 때는 polyline.remove를 통해서 하라고 나와있더군요
그런데 remove를 실행해도 새로운 경로를 그릴 때에는 이전 경로까지 모두 표시됩니다.
제가 생각한 문제가 polyline에 point들이 남아있어서 계속해서 표시되는 것 같아 polyline.getPoints를 통해서 결과를 확인했는데 remove 이후에도 각각의 지점이 남아있는 것을 확인했습니다.
remove를 통해서 이것들을 지우는 것이 아니었던 건가요 ? 이 점들을 지우거나 경로를 지우는 방법이 어떤게 있을까요 ? 정말 머리아파 죽겠습니다 도와주세요