0
폴리 라인을 제거하는 방법을 찾았지만 내 문제를 해결하지 못했습니다. 나는 이것을 게시함으로써 나는 이미 원하는 대답을 얻길 바랍니다. 여기 있습니다. 나는 내가 지금 운전 시작 함을 의미, 내가 btnFindPath 내 폴리 라인 쇼를 클릭하는 버튼을 생성다른 방법으로 폴리 라인 제거
btnFindPath = (Button) findViewById(R.id.btnStartStop);
btnFindPath.setTag(1);
btnFindPath.setText("Start");
btnFindPath.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int status = (Integer) v.getTag();
if (status == 1) {
Date date = new Date(mLastLocation.getTime());
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
timeStarted = dateFormat.format(date);
sendRequest();
buildGoogleApiClient();
btnFindPath.setText("Stop");
v.setTag(0);
} else {
dialog();
v.setTag(tag);
}
// 버튼이 메소드가 호출을 클릭합니다. 개인 무효 위치한 sendRequest() {
버튼 텍스트가 "중지"로 변경됩니다 클릭 String origin = etOrigin.getText().toString();
String destination = etDestination.getText().toString();
String mode = "mode=transit";
if (origin.isEmpty()) {
Toast.makeText(this, "Please enter origin address!", Toast.LENGTH_SHORT).show();
return;
}
if (destination.isEmpty()) {
Toast.makeText(this, "Please enter destination address!", Toast.LENGTH_SHORT).show();
return;
}
try {
new DirectionFinder(this, origin, destination, mode).execute();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
@Override
public void onDirectionFinderStart() {
progressDialog = ProgressDialog.show(this, "Please wait.",
"Finding direction..!", true);
if (originMarkers != null) {
for (Marker marker : originMarkers) {
marker.remove();
}
}
if (destinationMarkers != null) {
for (Marker marker : destinationMarkers) {
marker.remove();
}
}
if (polylinePaths != null) {
for (Polyline polyline : polylinePaths) {
polyline.remove();
}
}
}
public void onDirectionFinderSuccess(List<Route> routes) {
progressDialog.dismiss();
polylinePaths = new ArrayList<>();
originMarkers = new ArrayList<>();
destinationMarkers = new ArrayList<>();
for (Route route : routes) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(route.startLocation, 16));
((TextView) findViewById(R.id.tvDuration)).setText(route.duration.text);
((TextView) findViewById(R.id.tvDistance)).setText(route.distance.text);
originMarkers.add(mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.start_blue))
.title(route.startAddress)
.position(route.startLocation)));
destinationMarkers.add(mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.end_green))
.title(route.endAddress)
.position(route.endLocation)));
polylineOptions = new PolylineOptions().
geodesic(true).
color(Color.BLUE).
width(10);
for (int i = 0; i < route.points.size(); i++)
polylineOptions.add(route.points.get(i));
polylinePaths.add(mMap.addPolyline(polylineOptions));
}
}
public void dialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to end driving?")
.setCancelable(false)
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
btnFindPath.setText("Start");
tag = 1;
stopSending();
}
})
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
// when the dialog message was "yes" this method was called
private void stopSending() {
// this is where I want my code in deleting polyline be putted.
// this is my code but it doesn't work still my polyline was their
polylinePaths.remove(polylineOptions);
}
. 그것은 성공했지만 내 폴리 라인 또한 사라질 것이기를 바랍니다.