bugfix
This commit is contained in:
@@ -88,7 +88,7 @@ import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* 高德地图导航 Native View - 底部精简交互优化版
|
||||
* 高德地图导航
|
||||
*/
|
||||
public class NativeMapView implements PlatformView, LocationSource, AMapLocationListener,
|
||||
GeocodeSearch.OnGeocodeSearchListener, RouteSearch.OnRouteSearchListener, AMap.OnMarkerClickListener, Inputtips.InputtipsListener {
|
||||
@@ -115,6 +115,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
private LatLng currentLatLng;
|
||||
private String startName = "我的位置";
|
||||
private String endName = "";
|
||||
private String endAddress = "";
|
||||
private LatLng startPoint;
|
||||
private LatLng endPoint;
|
||||
private boolean isFirstLocation = true;
|
||||
@@ -130,117 +131,6 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
// 存储货车路线算法接口返回的数据
|
||||
private TruckRouteData truckRouteData;
|
||||
|
||||
// 货车路线算法数据Bean
|
||||
public static class TruckRouteData {
|
||||
public TruckDto truckDto;
|
||||
public String truckDtoStr;
|
||||
public DestinationSite destinationSite;
|
||||
public PathDto pathDto;
|
||||
public AlgorithmPath algorithmPath;
|
||||
public boolean isInvokeAlgorithm;
|
||||
}
|
||||
|
||||
public static class TruckDto {
|
||||
public boolean isRestriction;
|
||||
public String mvehicleSizeName;
|
||||
public String mvehicleAxisUnit;
|
||||
public String mcarNumber;
|
||||
public int mcarType;
|
||||
public String mvehicleHeight;
|
||||
public String mvehicleHeightUnit;
|
||||
public String mvehicleWeight;
|
||||
public String mvehicleWeightUnit;
|
||||
public String mvehicleLoad;
|
||||
public String mvehicleLoadUnit;
|
||||
public boolean mvehicleLoadSwitch;
|
||||
public String mvehicleWidth;
|
||||
public String mvehicleWidthUnit;
|
||||
public String mvehicleLength;
|
||||
public String mvehicleLengthUnit;
|
||||
public int mvehicleSize;
|
||||
public int mvehicleAxis;
|
||||
}
|
||||
|
||||
public static class PathDto {
|
||||
public int distance;
|
||||
public int duration;
|
||||
public String strategy;
|
||||
public String tolls;
|
||||
public int toll_distance;
|
||||
public int restriction;
|
||||
public int traffic_lights;
|
||||
public List<NaviPoint> naviList;
|
||||
}
|
||||
|
||||
public static class NaviPoint {
|
||||
public String name;
|
||||
public String poiId;
|
||||
public Coordinate coordinate;
|
||||
}
|
||||
|
||||
public static class Coordinate {
|
||||
public String longitude;
|
||||
public String latitude;
|
||||
}
|
||||
|
||||
public static class AlgorithmPath {
|
||||
public String tripRecommendationId;
|
||||
public String staId;
|
||||
public String tripOneWayPathId;
|
||||
public String tripReturnPathId;
|
||||
public String oneWayDis;
|
||||
public String returnDis;
|
||||
public String roundTripDis;
|
||||
public String oneWayTime;
|
||||
public String returnTime;
|
||||
public String roundTripTime;
|
||||
public String oneWayCost;
|
||||
public String returnCost;
|
||||
public String roundTripCost;
|
||||
public String oneWayLaborCost;
|
||||
public String returnLaborCost;
|
||||
public String roundTripLaborCost;
|
||||
public String oneWayChargerouteCost;
|
||||
public String returnChargerouteCost;
|
||||
public String roundTripChargerouteCost;
|
||||
public String oneWayHydrogenConsumption;
|
||||
public String returnLaborHydrogenConsumption;
|
||||
public String roundTripHydrogenConsumption;
|
||||
public String oneWayHydrogenCost;
|
||||
public String returnLaborHydrogenCost;
|
||||
public String roundTripHydrogenCost;
|
||||
public String hydrogenCost;
|
||||
public String hydrogenStaServiceTime;
|
||||
public String hydrogenStaRefuelingTime;
|
||||
public String hydrogenStaQueueTime;
|
||||
public String hydrogenStaServiceTimeCost;
|
||||
public String hydrogenStaRefuelingTimeCost;
|
||||
public String hydrogenStaQueueTimeCost;
|
||||
}
|
||||
|
||||
public static class DestinationSite {
|
||||
public String innerSiteId;
|
||||
public String name;
|
||||
public String shortName;
|
||||
public String siteNo;
|
||||
public String city;
|
||||
public String address;
|
||||
public String contact;
|
||||
public String phone;
|
||||
public String type;
|
||||
public String coOpMode;
|
||||
public String booking;
|
||||
public String siteStatus;
|
||||
public String siteStatusName;
|
||||
public String startBusiness;
|
||||
public String endBusiness;
|
||||
public String billingMethod;
|
||||
public String term;
|
||||
public String remark;
|
||||
public String longitude;
|
||||
public String latitude;
|
||||
public String distance;
|
||||
}
|
||||
|
||||
public NativeMapView(Context context, int id, Object args) {
|
||||
this.mContext = context;
|
||||
@@ -441,7 +331,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
// 规划成功,显示详情面板
|
||||
detailPanel.setVisibility(View.VISIBLE);
|
||||
tvStationName.setText(endName);
|
||||
tvStationAddr.setText(endInput.getText().toString());
|
||||
tvStationAddr.setText(endAddress);
|
||||
|
||||
String info = String.format("预计时间:%d分钟 | 行驶里程:%.1f公里 | 预计路费:%.0f元",
|
||||
path.getDuration() / 60, path.getDistance() / 1000f, path.getTolls());
|
||||
@@ -749,10 +639,9 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
endPoint = new LatLng(data.getDouble("latitude"), data.getDouble("longitude"));
|
||||
endName = data.getString("name");
|
||||
selectedSiteId = data.optString("id", "");
|
||||
String addr = data.optString("address", "");
|
||||
endAddress = data.optString("address", "");
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
endInput.setText(addr);
|
||||
markStation(endPoint, endName, selectedSiteId, true);
|
||||
markStation(endPoint, endName, endAddress, selectedSiteId, true);
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -789,7 +678,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
JSONObject item = array.getJSONObject(i);
|
||||
String id = item.getString("id");
|
||||
markStation(new LatLng(item.getDouble("latitude"), item.getDouble("longitude")),
|
||||
item.getString("name"), id, false);
|
||||
item.getString("name"), item.getString("address"), id, false);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
@@ -805,6 +694,118 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void markStation(LatLng latLng, String name, String address, String stationId,
|
||||
boolean isRecommend) {
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.position(latLng).title(name)
|
||||
.icon(BitmapDescriptorFactory.defaultMarker(
|
||||
isRecommend ? BitmapDescriptorFactory.HUE_RED
|
||||
: BitmapDescriptorFactory.HUE_GREEN));
|
||||
Marker m = aMap.addMarker(markerOptions);
|
||||
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("latLng", latLng);
|
||||
dataMap.put("stationId", stationId);
|
||||
dataMap.put("address", address);
|
||||
m.setObject(dataMap);
|
||||
|
||||
stationMarkers.add(m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMarkerClick(Marker marker) {
|
||||
Object obj = marker.getObject();
|
||||
|
||||
if (obj instanceof Map) {
|
||||
Map<String, Object> dataMap = (Map<String, Object>) obj;
|
||||
|
||||
// 获取坐标并赋值
|
||||
LatLng latLng = (LatLng) dataMap.get("latLng");
|
||||
if (latLng != null) {
|
||||
this.endPoint = latLng;
|
||||
}
|
||||
|
||||
// 获取站点ID并赋值
|
||||
String stationId = (String) dataMap.get("stationId");
|
||||
String address = (String) dataMap.get("address");
|
||||
if (stationId != null) {
|
||||
this.selectedSiteId = stationId;
|
||||
this.endAddress = address;
|
||||
}
|
||||
|
||||
// 更新 UI 和 业务逻辑
|
||||
endName = marker.getTitle();
|
||||
|
||||
// 需要传入当前位置以便接口计算路线
|
||||
if (mlocationClient != null && mlocationClient.getLastKnownLocation() != null) {
|
||||
fetchTruckRouteAlgorithm(mlocationClient.getLastKnownLocation());
|
||||
} else if (currentLatLng != null) {
|
||||
// 如果没有精准定位,尝试使用上次记录的经纬度
|
||||
AMapLocation tempLoc = new AMapLocation("");
|
||||
tempLoc.setLatitude(currentLatLng.latitude);
|
||||
tempLoc.setLongitude(currentLatLng.longitude);
|
||||
fetchTruckRouteAlgorithm(tempLoc);
|
||||
}
|
||||
|
||||
|
||||
// 计算路径
|
||||
calculateRouteBeforeNavi();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeocodeSearched(GeocodeResult r, int c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBusRouteSearched(BusRouteResult r, int c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalkRouteSearched(WalkRouteResult r, int c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRideRouteSearched(RideRouteResult r, int c) {
|
||||
}
|
||||
|
||||
private Activity getActivityFromContext(Context context) {
|
||||
if (context instanceof Activity)
|
||||
return (Activity) context;
|
||||
if (context instanceof android.content.ContextWrapper)
|
||||
return getActivityFromContext(((android.content.ContextWrapper) context).getBaseContext());
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(Bundle out) {
|
||||
mapView.onSaveInstanceState(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (mlocationClient != null) {
|
||||
mlocationClient.stopLocation();
|
||||
mlocationClient.onDestroy();
|
||||
}
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析接口返回的data数据
|
||||
*/
|
||||
@@ -948,112 +949,115 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
return truckRouteData;
|
||||
}
|
||||
|
||||
private void markStation(LatLng latLng, String name, String stationId,
|
||||
boolean isRecommend) {
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.position(latLng).title(name)
|
||||
.icon(BitmapDescriptorFactory.defaultMarker(
|
||||
isRecommend ? BitmapDescriptorFactory.HUE_RED
|
||||
: BitmapDescriptorFactory.HUE_GREEN));
|
||||
Marker m = aMap.addMarker(markerOptions);
|
||||
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("latLng", latLng);
|
||||
dataMap.put("stationId", stationId);
|
||||
m.setObject(dataMap);
|
||||
|
||||
stationMarkers.add(m);
|
||||
// 货车路线算法数据Bean
|
||||
public static class TruckRouteData {
|
||||
public TruckDto truckDto;
|
||||
public String truckDtoStr;
|
||||
public DestinationSite destinationSite;
|
||||
public PathDto pathDto;
|
||||
public AlgorithmPath algorithmPath;
|
||||
public boolean isInvokeAlgorithm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMarkerClick(Marker marker) {
|
||||
Object obj = marker.getObject();
|
||||
|
||||
if (obj instanceof Map) {
|
||||
Map<String, Object> dataMap = (Map<String, Object>) obj;
|
||||
|
||||
// 获取坐标并赋值
|
||||
LatLng latLng = (LatLng) dataMap.get("latLng");
|
||||
if (latLng != null) {
|
||||
this.endPoint = latLng;
|
||||
}
|
||||
|
||||
// 获取站点ID并赋值
|
||||
String stationId = (String) dataMap.get("stationId");
|
||||
if (stationId != null) {
|
||||
this.selectedSiteId = stationId;
|
||||
}
|
||||
|
||||
// 更新 UI 和 业务逻辑
|
||||
endName = marker.getTitle();
|
||||
endInput.setText(endName);
|
||||
|
||||
// 需要传入当前位置以便接口计算路线
|
||||
if (mlocationClient != null && mlocationClient.getLastKnownLocation() != null) {
|
||||
fetchTruckRouteAlgorithm(mlocationClient.getLastKnownLocation());
|
||||
} else if (currentLatLng != null) {
|
||||
// 如果没有精准定位,尝试使用上次记录的经纬度
|
||||
AMapLocation tempLoc = new AMapLocation("");
|
||||
tempLoc.setLatitude(currentLatLng.latitude);
|
||||
tempLoc.setLongitude(currentLatLng.longitude);
|
||||
fetchTruckRouteAlgorithm(tempLoc);
|
||||
}
|
||||
|
||||
|
||||
// 计算路径
|
||||
calculateRouteBeforeNavi();
|
||||
}
|
||||
|
||||
return true;
|
||||
public static class TruckDto {
|
||||
public boolean isRestriction;
|
||||
public String mvehicleSizeName;
|
||||
public String mvehicleAxisUnit;
|
||||
public String mcarNumber;
|
||||
public int mcarType;
|
||||
public String mvehicleHeight;
|
||||
public String mvehicleHeightUnit;
|
||||
public String mvehicleWeight;
|
||||
public String mvehicleWeightUnit;
|
||||
public String mvehicleLoad;
|
||||
public String mvehicleLoadUnit;
|
||||
public boolean mvehicleLoadSwitch;
|
||||
public String mvehicleWidth;
|
||||
public String mvehicleWidthUnit;
|
||||
public String mvehicleLength;
|
||||
public String mvehicleLengthUnit;
|
||||
public int mvehicleSize;
|
||||
public int mvehicleAxis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeocodeSearched(GeocodeResult r, int c) {
|
||||
public static class PathDto {
|
||||
public int distance;
|
||||
public int duration;
|
||||
public String strategy;
|
||||
public String tolls;
|
||||
public int toll_distance;
|
||||
public int restriction;
|
||||
public int traffic_lights;
|
||||
public List<NaviPoint> naviList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBusRouteSearched(BusRouteResult r, int c) {
|
||||
public static class NaviPoint {
|
||||
public String name;
|
||||
public String poiId;
|
||||
public Coordinate coordinate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalkRouteSearched(WalkRouteResult r, int c) {
|
||||
public static class Coordinate {
|
||||
public String longitude;
|
||||
public String latitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRideRouteSearched(RideRouteResult r, int c) {
|
||||
public static class AlgorithmPath {
|
||||
public String tripRecommendationId;
|
||||
public String staId;
|
||||
public String tripOneWayPathId;
|
||||
public String tripReturnPathId;
|
||||
public String oneWayDis;
|
||||
public String returnDis;
|
||||
public String roundTripDis;
|
||||
public String oneWayTime;
|
||||
public String returnTime;
|
||||
public String roundTripTime;
|
||||
public String oneWayCost;
|
||||
public String returnCost;
|
||||
public String roundTripCost;
|
||||
public String oneWayLaborCost;
|
||||
public String returnLaborCost;
|
||||
public String roundTripLaborCost;
|
||||
public String oneWayChargerouteCost;
|
||||
public String returnChargerouteCost;
|
||||
public String roundTripChargerouteCost;
|
||||
public String oneWayHydrogenConsumption;
|
||||
public String returnLaborHydrogenConsumption;
|
||||
public String roundTripHydrogenConsumption;
|
||||
public String oneWayHydrogenCost;
|
||||
public String returnLaborHydrogenCost;
|
||||
public String roundTripHydrogenCost;
|
||||
public String hydrogenCost;
|
||||
public String hydrogenStaServiceTime;
|
||||
public String hydrogenStaRefuelingTime;
|
||||
public String hydrogenStaQueueTime;
|
||||
public String hydrogenStaServiceTimeCost;
|
||||
public String hydrogenStaRefuelingTimeCost;
|
||||
public String hydrogenStaQueueTimeCost;
|
||||
}
|
||||
|
||||
private Activity getActivityFromContext(Context context) {
|
||||
if (context instanceof Activity)
|
||||
return (Activity) context;
|
||||
if (context instanceof android.content.ContextWrapper)
|
||||
return getActivityFromContext(((android.content.ContextWrapper) context).getBaseContext());
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(Bundle out) {
|
||||
mapView.onSaveInstanceState(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (mlocationClient != null) {
|
||||
mlocationClient.stopLocation();
|
||||
mlocationClient.onDestroy();
|
||||
}
|
||||
mapView.onDestroy();
|
||||
public static class DestinationSite {
|
||||
public String innerSiteId;
|
||||
public String name;
|
||||
public String shortName;
|
||||
public String siteNo;
|
||||
public String city;
|
||||
public String address;
|
||||
public String contact;
|
||||
public String phone;
|
||||
public String type;
|
||||
public String coOpMode;
|
||||
public String booking;
|
||||
public String siteStatus;
|
||||
public String siteStatusName;
|
||||
public String startBusiness;
|
||||
public String endBusiness;
|
||||
public String billingMethod;
|
||||
public String term;
|
||||
public String remark;
|
||||
public String longitude;
|
||||
public String latitude;
|
||||
public String distance;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user