我做谷歌地圖與谷歌方向我使用類別http://www.akexorcist.com/2015/12/google-direction-library-for-android-en.html 某人爲谷歌方向建立。一切都很好, 和折線顯示在地圖上。但是當我需要點擊另一個方向時,例如行走方向或駕駛方向,我會在地圖上看到2條折線,而我只想看到當前的折線。需要刪除最後一條折線並創建當前折線
這裏我創建折線 並在開始時刪除折線,然後折線根本不顯示。 我不想那樣。我希望當我點擊其他按鈕時,折線將被刪除。 我嘗試把,polyline.remove();按鈕單擊其他但問題,如果,polyline.remove();在圓括號之外,polyline.remove();不要刪除折線。我需要調用polyline.remove();當我點擊其他按鈕,但我卡住了。 這裏是代碼:
switch (direction.getStatus()) {
case RequestResult.OK:
Route route = direction.getRouteList().get(0);
Leg leg = route.getLegList().get(0);
ArrayList<LatLng> pointList = leg.getDirectionPoint();
List<Step> stepList = direction.getRouteList().get(0).getLegList().get(0).getStepList();
ArrayList<PolylineOptions> polylineOptionList = DirectionConverter.createTransitPolyline(this, stepList, 5, Color.RED, 3, Color.BLUE);
for (PolylineOptions polylineOption : polylineOptionList) {
polyline = mMap.addPolyline(polylineOption);
polyline.remove();
}
break;
2.當我在行走按鈕,單擊希望過境折線將刪除 我們剛纔所有的時間,只有一個在地圖上折線。 我該怎麼做?
bWalking.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (locationGpsLatLng == null) {
Toast.makeText(MapsActivity.this, "Need GPS location", `enter code here`Toast.LENGTH_SHORT).show();{
return;
}
}
if (markerLocation == null) {
Toast.makeText(MapsActivity.this, "Type on marker bathroom for destination", Toast.LENGTH_SHORT).show();
} else {
sendRequestWalkingDirection();
}
};
private void sendRequestWalkingDirection() {
GoogleDirection.withServerKey(APIKEY)
.from(locationGpsLatLng)
.to(markerLocation)
.transportMode(TransportMode.WALKING)
.execute(new DirectionCallback() {
@Override
public void onDirectionSuccess(Direction direction, String rawBody) {
Log.d("onDirectionSuccess", "status: " + direction.getStatus());
requestOk(direction, rawBody);
mMap.addMarker(new MarkerOptions().position(locationGpsLatLng).draggable(false).icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(locationGpsLatLng, 15);
mMap.animateCamera(cameraUpdate);
}
@Override
public void onDirectionFailure(Throwable t) {
return;
}
});
}
});
mMap.clear();清除所有地圖包括我所有的標記其對我不好 –
我已更新我的回答 – Wilik
其工作非常感謝。你很棒!! –