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);
}
//ボタンは、このメソッドが呼び出されたクリックです。 ます。private voidの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);
}
テキストは "停止" に変わります。成功しましたが、ポリラインもまた消えてしまいます。