优化
This commit is contained in:
@@ -287,6 +287,8 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
String name = tip.getName();
|
||||
String district = tip.getDistrict();
|
||||
endName = name;
|
||||
endAddress = tip.getAddress();
|
||||
isGetInputtips = true;
|
||||
isUserSelectedDestination = true; // 标识用户手动选择了目的地
|
||||
isProgrammaticTextChange = true; // 标识是程序自动设置文本
|
||||
endInput.setText(district != null && !district.isEmpty() ? name + " " + district : name);
|
||||
@@ -525,6 +527,8 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
return panel;
|
||||
}
|
||||
|
||||
private boolean isGetInputtips = false;
|
||||
|
||||
private void calculateRouteBeforeNavi() {
|
||||
if (startPoint == null) {
|
||||
Toast.makeText(mContext, "正在定位...", Toast.LENGTH_SHORT).show();
|
||||
@@ -536,7 +540,18 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
return;
|
||||
}
|
||||
|
||||
fetchTruckRouteAlgorithm(mLoc);
|
||||
//如果是输入地址提示内容
|
||||
|
||||
if (isGetInputtips) {
|
||||
// 开始规划前隐藏输入框面板
|
||||
searchArea.setVisibility(View.GONE);
|
||||
|
||||
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(new LatLonPoint(startPoint.latitude, startPoint.longitude), new LatLonPoint(endPoint.latitude, endPoint.longitude));
|
||||
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DRIVING_SINGLE_DEFAULT, null, null, "");
|
||||
routeSearch.calculateDriveRouteAsyn(query);
|
||||
} else {
|
||||
fetchTruckRouteAlgorithm(mLoc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -584,34 +599,58 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
|
||||
@Override
|
||||
public void onDriveRouteSearched(DriveRouteResult result, int rCode) {
|
||||
if (rCode == AMapException.CODE_AMAP_SUCCESS && result != null && !result.getPaths().isEmpty()) {
|
||||
DrivePath path = result.getPaths().get(0);
|
||||
|
||||
// 规划成功,显示详情面板,隐藏模式选择
|
||||
detailPanel.setVisibility(View.VISIBLE);
|
||||
planToggleBtn.setVisibility(View.GONE);
|
||||
modeMenu.setVisibility(View.GONE);
|
||||
|
||||
tvStationName.setText(endName);
|
||||
tvStationAddr.setText(endAddress);
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
|
||||
double distanceKm = path.getDistance() / 1000f;
|
||||
long durationMin = path.getDuration() / 60;
|
||||
double tolls = path.getTolls();
|
||||
String hydrogenCost = truckRouteData.algorithmPath.hydrogenCost;
|
||||
if (rCode == AMapException.CODE_AMAP_SUCCESS && result != null && !result.getPaths().isEmpty()) {
|
||||
DrivePath path = result.getPaths().get(0);
|
||||
|
||||
tvDuration.setText("预计时间:" + durationMin + "分钟");
|
||||
tvDistance.setText("行驶里程:" + String.format("%.1f", distanceKm) + "公里");
|
||||
tvTolls.setText("过路费:" + (int) tolls + "元");
|
||||
tvTollsFuel.setText("加氢费用:" + hydrogenCost + "元");
|
||||
// 规划成功,显示详情面板,隐藏模式选择
|
||||
if (detailPanel != null)
|
||||
detailPanel.setVisibility(View.VISIBLE);
|
||||
if (planToggleBtn != null)
|
||||
planToggleBtn.setVisibility(View.GONE);
|
||||
if (modeMenu != null)
|
||||
modeMenu.setVisibility(View.GONE);
|
||||
|
||||
aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(endPoint, 13f));
|
||||
} else {
|
||||
// 规划失败回退面板
|
||||
searchArea.setVisibility(View.VISIBLE);
|
||||
Toast.makeText(mContext, "路径规划失败: " + rCode, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
tvStationName.setText(endName);
|
||||
tvStationAddr.setText(endAddress);
|
||||
|
||||
double distanceKm = path.getDistance() / 1000f;
|
||||
long durationMin = path.getDuration() / 60;
|
||||
double tolls = path.getTolls();
|
||||
|
||||
String hydrogenCost = "--"; // 默认显示横线
|
||||
try {
|
||||
// 增加多级非空校验,防止点击搜索条目时崩溃
|
||||
if (truckRouteData != null &&
|
||||
truckRouteData.algorithmPath != null &&
|
||||
truckRouteData.algorithmPath.hydrogenCost != null &&
|
||||
!truckRouteData.algorithmPath.hydrogenCost.isEmpty()) {
|
||||
hydrogenCost = truckRouteData.algorithmPath.hydrogenCost;
|
||||
}
|
||||
|
||||
tvDuration.setText("预计时间:" + durationMin + "分钟");
|
||||
tvDistance.setText("行驶里程:" + String.format("%.1f", distanceKm) + "公里");
|
||||
tvTolls.setText("过路费:" + (int) tolls + "元");
|
||||
tvTollsFuel.setText("加氢费用:" + (isGetInputtips ? "--" : hydrogenCost) + "元");
|
||||
|
||||
isGetInputtips = false;
|
||||
|
||||
aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(endPoint, 13f));
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "获取加氢费用失败", e);
|
||||
}
|
||||
} else {
|
||||
// 规划失败回退面板
|
||||
searchArea.setVisibility(View.VISIBLE);
|
||||
Toast.makeText(mContext, "路径规划失败: " + rCode, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void startRouteSearch() {
|
||||
@@ -679,16 +718,20 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
//车辆信息
|
||||
AMapCarInfo carInfo = new AMapCarInfo();
|
||||
carInfo.setCarNumber(plateNumber);
|
||||
carInfo.setCarType(String.valueOf(truckRouteData.truckDto.mcarType));
|
||||
carInfo.setVehicleAxis(String.valueOf(truckRouteData.truckDto.mvehicleAxis));
|
||||
carInfo.setVehicleHeight(truckRouteData.truckDto.mvehicleHeight);
|
||||
carInfo.setVehicleLength(truckRouteData.truckDto.mvehicleLength);
|
||||
carInfo.setVehicleWidth(truckRouteData.truckDto.mvehicleWidth);
|
||||
carInfo.setVehicleSize(String.valueOf(truckRouteData.truckDto.mvehicleSize));
|
||||
carInfo.setVehicleLoad(truckRouteData.truckDto.mvehicleLoad);
|
||||
carInfo.setVehicleWeight(truckRouteData.truckDto.mvehicleWeight);
|
||||
carInfo.setRestriction(truckRouteData.truckDto.isRestriction);
|
||||
carInfo.setVehicleLoadSwitch(truckRouteData.truckDto.mvehicleLoadSwitch);
|
||||
|
||||
if (truckRouteData != null) {
|
||||
carInfo.setCarType(String.valueOf(truckRouteData.truckDto.mcarType));
|
||||
carInfo.setVehicleAxis(String.valueOf(truckRouteData.truckDto.mvehicleAxis));
|
||||
carInfo.setVehicleHeight(truckRouteData.truckDto.mvehicleHeight);
|
||||
carInfo.setVehicleLength(truckRouteData.truckDto.mvehicleLength);
|
||||
carInfo.setVehicleWidth(truckRouteData.truckDto.mvehicleWidth);
|
||||
carInfo.setVehicleSize(String.valueOf(truckRouteData.truckDto.mvehicleSize));
|
||||
carInfo.setVehicleLoad(truckRouteData.truckDto.mvehicleLoad);
|
||||
carInfo.setVehicleWeight(truckRouteData.truckDto.mvehicleWeight);
|
||||
carInfo.setRestriction(truckRouteData.truckDto.isRestriction);
|
||||
carInfo.setVehicleLoadSwitch(truckRouteData.truckDto.mvehicleLoadSwitch);
|
||||
}
|
||||
|
||||
|
||||
// 检查途径点数量,决定使用哪种导航方式
|
||||
int wayPointsCount = waysPoiIds.size();
|
||||
@@ -801,12 +844,17 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
|
||||
dismissLoading();
|
||||
|
||||
// 开始规划前隐藏输入框面板
|
||||
searchArea.setVisibility(View.GONE);
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 开始规划前隐藏输入框面板
|
||||
searchArea.setVisibility(View.GONE);
|
||||
|
||||
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(new LatLonPoint(startPoint.latitude, startPoint.longitude), new LatLonPoint(endPoint.latitude, endPoint.longitude));
|
||||
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DRIVING_SINGLE_DEFAULT, null, null, "");
|
||||
routeSearch.calculateDriveRouteAsyn(query);
|
||||
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(new LatLonPoint(startPoint.latitude, startPoint.longitude), new LatLonPoint(endPoint.latitude, endPoint.longitude));
|
||||
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DRIVING_SINGLE_DEFAULT, null, null, "");
|
||||
routeSearch.calculateDriveRouteAsyn(query);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
dismissLoading();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user