bugfix
This commit is contained in:
@@ -88,7 +88,7 @@ import okhttp3.RequestBody;
|
|||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 高德地图导航 Native View - 底部精简交互优化版
|
* 高德地图导航
|
||||||
*/
|
*/
|
||||||
public class NativeMapView implements PlatformView, LocationSource, AMapLocationListener,
|
public class NativeMapView implements PlatformView, LocationSource, AMapLocationListener,
|
||||||
GeocodeSearch.OnGeocodeSearchListener, RouteSearch.OnRouteSearchListener, AMap.OnMarkerClickListener, Inputtips.InputtipsListener {
|
GeocodeSearch.OnGeocodeSearchListener, RouteSearch.OnRouteSearchListener, AMap.OnMarkerClickListener, Inputtips.InputtipsListener {
|
||||||
@@ -115,6 +115,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
private LatLng currentLatLng;
|
private LatLng currentLatLng;
|
||||||
private String startName = "我的位置";
|
private String startName = "我的位置";
|
||||||
private String endName = "";
|
private String endName = "";
|
||||||
|
private String endAddress = "";
|
||||||
private LatLng startPoint;
|
private LatLng startPoint;
|
||||||
private LatLng endPoint;
|
private LatLng endPoint;
|
||||||
private boolean isFirstLocation = true;
|
private boolean isFirstLocation = true;
|
||||||
@@ -130,117 +131,6 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
// 存储货车路线算法接口返回的数据
|
// 存储货车路线算法接口返回的数据
|
||||||
private TruckRouteData truckRouteData;
|
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) {
|
public NativeMapView(Context context, int id, Object args) {
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
@@ -441,7 +331,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
// 规划成功,显示详情面板
|
// 规划成功,显示详情面板
|
||||||
detailPanel.setVisibility(View.VISIBLE);
|
detailPanel.setVisibility(View.VISIBLE);
|
||||||
tvStationName.setText(endName);
|
tvStationName.setText(endName);
|
||||||
tvStationAddr.setText(endInput.getText().toString());
|
tvStationAddr.setText(endAddress);
|
||||||
|
|
||||||
String info = String.format("预计时间:%d分钟 | 行驶里程:%.1f公里 | 预计路费:%.0f元",
|
String info = String.format("预计时间:%d分钟 | 行驶里程:%.1f公里 | 预计路费:%.0f元",
|
||||||
path.getDuration() / 60, path.getDistance() / 1000f, path.getTolls());
|
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"));
|
endPoint = new LatLng(data.getDouble("latitude"), data.getDouble("longitude"));
|
||||||
endName = data.getString("name");
|
endName = data.getString("name");
|
||||||
selectedSiteId = data.optString("id", "");
|
selectedSiteId = data.optString("id", "");
|
||||||
String addr = data.optString("address", "");
|
endAddress = data.optString("address", "");
|
||||||
new Handler(Looper.getMainLooper()).post(() -> {
|
new Handler(Looper.getMainLooper()).post(() -> {
|
||||||
endInput.setText(addr);
|
markStation(endPoint, endName, endAddress, selectedSiteId, true);
|
||||||
markStation(endPoint, endName, selectedSiteId, true);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -789,7 +678,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
JSONObject item = array.getJSONObject(i);
|
JSONObject item = array.getJSONObject(i);
|
||||||
String id = item.getString("id");
|
String id = item.getString("id");
|
||||||
markStation(new LatLng(item.getDouble("latitude"), item.getDouble("longitude")),
|
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) {
|
} 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数据
|
* 解析接口返回的data数据
|
||||||
*/
|
*/
|
||||||
@@ -948,112 +949,115 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
return truckRouteData;
|
return truckRouteData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markStation(LatLng latLng, String name, String stationId,
|
// 货车路线算法数据Bean
|
||||||
boolean isRecommend) {
|
public static class TruckRouteData {
|
||||||
MarkerOptions markerOptions = new MarkerOptions()
|
public TruckDto truckDto;
|
||||||
.position(latLng).title(name)
|
public String truckDtoStr;
|
||||||
.icon(BitmapDescriptorFactory.defaultMarker(
|
public DestinationSite destinationSite;
|
||||||
isRecommend ? BitmapDescriptorFactory.HUE_RED
|
public PathDto pathDto;
|
||||||
: BitmapDescriptorFactory.HUE_GREEN));
|
public AlgorithmPath algorithmPath;
|
||||||
Marker m = aMap.addMarker(markerOptions);
|
public boolean isInvokeAlgorithm;
|
||||||
|
|
||||||
Map<String, Object> dataMap = new HashMap<>();
|
|
||||||
dataMap.put("latLng", latLng);
|
|
||||||
dataMap.put("stationId", stationId);
|
|
||||||
m.setObject(dataMap);
|
|
||||||
|
|
||||||
stationMarkers.add(m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static class TruckDto {
|
||||||
public boolean onMarkerClick(Marker marker) {
|
public boolean isRestriction;
|
||||||
Object obj = marker.getObject();
|
public String mvehicleSizeName;
|
||||||
|
public String mvehicleAxisUnit;
|
||||||
if (obj instanceof Map) {
|
public String mcarNumber;
|
||||||
Map<String, Object> dataMap = (Map<String, Object>) obj;
|
public int mcarType;
|
||||||
|
public String mvehicleHeight;
|
||||||
// 获取坐标并赋值
|
public String mvehicleHeightUnit;
|
||||||
LatLng latLng = (LatLng) dataMap.get("latLng");
|
public String mvehicleWeight;
|
||||||
if (latLng != null) {
|
public String mvehicleWeightUnit;
|
||||||
this.endPoint = latLng;
|
public String mvehicleLoad;
|
||||||
}
|
public String mvehicleLoadUnit;
|
||||||
|
public boolean mvehicleLoadSwitch;
|
||||||
// 获取站点ID并赋值
|
public String mvehicleWidth;
|
||||||
String stationId = (String) dataMap.get("stationId");
|
public String mvehicleWidthUnit;
|
||||||
if (stationId != null) {
|
public String mvehicleLength;
|
||||||
this.selectedSiteId = stationId;
|
public String mvehicleLengthUnit;
|
||||||
}
|
public int mvehicleSize;
|
||||||
|
public int mvehicleAxis;
|
||||||
// 更新 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static class PathDto {
|
||||||
public void onGeocodeSearched(GeocodeResult r, int c) {
|
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 static class NaviPoint {
|
||||||
public void onBusRouteSearched(BusRouteResult r, int c) {
|
public String name;
|
||||||
|
public String poiId;
|
||||||
|
public Coordinate coordinate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static class Coordinate {
|
||||||
public void onWalkRouteSearched(WalkRouteResult r, int c) {
|
public String longitude;
|
||||||
|
public String latitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static class AlgorithmPath {
|
||||||
public void onRideRouteSearched(RideRouteResult r, int c) {
|
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) {
|
public static class DestinationSite {
|
||||||
if (context instanceof Activity)
|
public String innerSiteId;
|
||||||
return (Activity) context;
|
public String name;
|
||||||
if (context instanceof android.content.ContextWrapper)
|
public String shortName;
|
||||||
return getActivityFromContext(((android.content.ContextWrapper) context).getBaseContext());
|
public String siteNo;
|
||||||
return null;
|
public String city;
|
||||||
}
|
public String address;
|
||||||
|
public String contact;
|
||||||
public void onResume() {
|
public String phone;
|
||||||
mapView.onResume();
|
public String type;
|
||||||
}
|
public String coOpMode;
|
||||||
|
public String booking;
|
||||||
public void onPause() {
|
public String siteStatus;
|
||||||
mapView.onPause();
|
public String siteStatusName;
|
||||||
}
|
public String startBusiness;
|
||||||
|
public String endBusiness;
|
||||||
public void onSaveInstanceState(Bundle out) {
|
public String billingMethod;
|
||||||
mapView.onSaveInstanceState(out);
|
public String term;
|
||||||
}
|
public String remark;
|
||||||
|
public String longitude;
|
||||||
@Override
|
public String latitude;
|
||||||
public View getView() {
|
public String distance;
|
||||||
return container;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
if (mlocationClient != null) {
|
|
||||||
mlocationClient.stopLocation();
|
|
||||||
mlocationClient.onDestroy();
|
|
||||||
}
|
|
||||||
mapView.onDestroy();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user