diff --git a/ln_jq_app/android/app/src/main/java/com/lnkj/ln_jq_app/NativeMapView.java b/ln_jq_app/android/app/src/main/java/com/lnkj/ln_jq_app/NativeMapView.java index ed377cc..6932c81 100644 --- a/ln_jq_app/android/app/src/main/java/com/lnkj/ln_jq_app/NativeMapView.java +++ b/ln_jq_app/android/app/src/main/java/com/lnkj/ln_jq_app/NativeMapView.java @@ -5,10 +5,13 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; +import android.graphics.Typeface; import android.graphics.drawable.GradientDrawable; import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.text.Editable; +import android.text.TextWatcher; import android.util.Log; import android.util.TypedValue; import android.view.Gravity; @@ -20,6 +23,7 @@ import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.LinearLayout; +import android.widget.TextView; import android.widget.Toast; import com.amap.api.location.AMapLocation; @@ -43,10 +47,7 @@ import com.amap.api.navi.AmapNaviPage; import com.amap.api.navi.AmapNaviParams; import com.amap.api.navi.AmapNaviType; import com.amap.api.navi.AmapPageType; -import com.amap.api.navi.INaviInfoCallback; -import com.amap.api.navi.enums.PathPlanningStrategy; import com.amap.api.navi.model.AMapCarInfo; -import com.amap.api.navi.model.AMapNaviLocation; import com.amap.api.services.core.AMapException; import com.amap.api.services.core.LatLonPoint; import com.amap.api.services.geocoder.GeocodeResult; @@ -54,7 +55,11 @@ import com.amap.api.services.geocoder.GeocodeSearch; import com.amap.api.services.geocoder.RegeocodeAddress; import com.amap.api.services.geocoder.RegeocodeQuery; import com.amap.api.services.geocoder.RegeocodeResult; +import com.amap.api.services.help.Inputtips; +import com.amap.api.services.help.InputtipsQuery; +import com.amap.api.services.help.Tip; import com.amap.api.services.route.BusRouteResult; +import com.amap.api.services.route.DrivePath; import com.amap.api.services.route.DriveRouteResult; import com.amap.api.services.route.RideRouteResult; import com.amap.api.services.route.RouteSearch; @@ -78,33 +83,33 @@ import okhttp3.RequestBody; import okhttp3.Response; /** - * 高德地图导航 + * 高德地图导航 Native View - 底部精简交互优化版 */ public class NativeMapView implements PlatformView, LocationSource, AMapLocationListener, - GeocodeSearch.OnGeocodeSearchListener, RouteSearch.OnRouteSearchListener, AMap.OnMarkerClickListener { + GeocodeSearch.OnGeocodeSearchListener, RouteSearch.OnRouteSearchListener, AMap.OnMarkerClickListener, Inputtips.InputtipsListener { private static final String TAG = "NativeMapView"; private final FrameLayout container; - - // 地图相关 private MapView mapView; private AMap aMap; private OnLocationChangedListener mListener; - // 定位相关 private AMapLocationClient mlocationClient; private final Context mContext; - private Activity mActivity; // 保存Activity引用用于导航 + private Activity mActivity; private GeocodeSearch geocoderSearch; private RouteSearch routeSearch; private final OkHttpClient httpClient = new OkHttpClient(); // UI组件 - private EditText startInput; private EditText endInput; + private LinearLayout searchArea; // 规划路线面板 + private LinearLayout detailPanel; // 详情面板 + private TextView tvStationName, tvStationAddr, tvRouteInfo; + private LatLng currentLatLng; private String startName = "我的位置"; - private String endName = "目的地"; + private String endName = ""; private LatLng startPoint; private LatLng endPoint; private boolean isFirstLocation = true; @@ -112,8 +117,6 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation public NativeMapView(Context context, int id, Object args) { this.mContext = context; - - // 尝试获取Activity引用 mActivity = getActivityFromContext(context); MapsInitializer.updatePrivacyShow(context, true, true); @@ -127,24 +130,17 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation mapView.onCreate(null); aMap = mapView.getMap(); - container.addView(mapView, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + container.addView(mapView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); initServices(context); initOverlays(context); setupMapUi(); - // 通知MainActivity if (context instanceof MainActivity) { ((MainActivity) context).setMapView(this); } - - Log.d(TAG, "NativeMapView初始化完成"); } - /** - * 初始化服务 - */ private void initServices(Context context) { try { geocoderSearch = new GeocodeSearch(context); @@ -156,75 +152,209 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation } } - /** - * 初始化覆盖层UI - */ private void initOverlays(Context context) { - LinearLayout searchBox = new LinearLayout(context); - searchBox.setOrientation(LinearLayout.VERTICAL); - searchBox.setBackground(getRoundedDrawable(Color.WHITE, 12)); - searchBox.setElevation(dp2px(8)); - int p = dp2px(15); - searchBox.setPadding(p, p, p, p); - searchBox.setClickable(true); - searchBox.setFocusable(true); + // --- 底部主容器 (包含两个互斥显示的面板) --- + LinearLayout bottomContainer = new LinearLayout(context); + bottomContainer.setOrientation(LinearLayout.VERTICAL); + bottomContainer.setGravity(Gravity.BOTTOM); - startInput = createInput(context, "起点: 正在定位..."); - searchBox.addView(startInput); + // 1. 详情面板 (用于显示加氢站详细信息,初始隐藏) + detailPanel = createDetailPanel(context); + detailPanel.setVisibility(View.GONE); + bottomContainer.addView(detailPanel); + + // 2. 搜索规划面板 (初始显示) + searchArea = new LinearLayout(context); + searchArea.setOrientation(LinearLayout.VERTICAL); + searchArea.setBackground(getRoundedDrawable(Color.WHITE, 16)); + searchArea.setElevation(dp2px(10)); + int p = dp2px(15); + searchArea.setPadding(p, p, p, p); + + endInput = new EditText(context); + endInput.setHint("请输入目的地,不输入则自动匹配推荐加氢站"); + endInput.setTextSize(13); + endInput.setHintTextColor(Color.LTGRAY); + endInput.setPadding(dp2px(12), dp2px(12), dp2px(12), dp2px(12)); + endInput.setBackground(getRoundedDrawable(Color.parseColor("#F8F8F8"), 8)); + endInput.setSingleLine(true); + endInput.setImeOptions(EditorInfo.IME_ACTION_SEARCH); + endInput.addTextChangedListener(new TextWatcher() { + @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + @Override public void onTextChanged(CharSequence s, int start, int before, int count) { + if (s.length() > 1) { + InputtipsQuery query = new InputtipsQuery(s.toString(), ""); + query.setCityLimit(true); + Inputtips inputtips = new Inputtips(mContext, query); + inputtips.setInputtipsListener(NativeMapView.this); + inputtips.requestInputtipsAsyn(); + } + } + @Override public void afterTextChanged(Editable s) {} + }); + searchArea.addView(endInput); View vSpace = new View(context); - searchBox.addView(vSpace, new LinearLayout.LayoutParams(1, dp2px(10))); + searchArea.addView(vSpace, new LinearLayout.LayoutParams(1, dp2px(12))); - LinearLayout endRow = new LinearLayout(context); - endRow.setOrientation(LinearLayout.HORIZONTAL); - endRow.setGravity(Gravity.CENTER_VERTICAL); + Button planBtn = new Button(context); + planBtn.setText("规划路线"); + planBtn.setTextColor(Color.WHITE); + planBtn.setTypeface(Typeface.DEFAULT_BOLD); + planBtn.setBackground(getRoundedDrawable(Color.parseColor("#017143"), 10)); + planBtn.setOnClickListener(v -> calculateRouteBeforeNavi()); + searchArea.addView(planBtn, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp2px(48))); - endInput = createInput(context, "终点: 请输入目的地"); - endRow.addView(endInput, new LinearLayout.LayoutParams(0, dp2px(42), 1f)); + bottomContainer.addView(searchArea); - Button routeBtn = new Button(context); - routeBtn.setText("路径规划"); - routeBtn.setTextColor(Color.WHITE); - routeBtn.setAllCaps(false); - routeBtn.setTextSize(14); - routeBtn.setBackground(getRoundedDrawable(Color.parseColor("#017143"), 6)); - routeBtn.setOnClickListener(v -> startRouteSearch()); - endRow.addView(routeBtn, new LinearLayout.LayoutParams(dp2px(90), dp2px(42))); - - searchBox.addView(endRow); - - FrameLayout.LayoutParams searchParams = new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - searchParams.setMargins(dp2px(15), dp2px(50), dp2px(15), 0); - container.addView(searchBox, searchParams); + // 设置统一的底部间距 + FrameLayout.LayoutParams bottomParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + bottomParams.gravity = Gravity.BOTTOM; + bottomParams.setMargins(dp2px(12), 0, dp2px(12), dp2px(65)); + container.addView(bottomContainer, bottomParams); + // --- 右下角定位按钮 --- ImageButton locBtn = new ImageButton(context); locBtn.setImageResource(android.R.drawable.ic_menu_mylocation); - locBtn.setBackground(getRoundedDrawable(Color.WHITE, 30)); + locBtn.setBackground(getRoundedDrawable(Color.WHITE, 25)); locBtn.setElevation(dp2px(4)); locBtn.setOnClickListener(v -> { - if (currentLatLng != null) { - aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 15f)); - } + if (currentLatLng != null) aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 15f)); }); - FrameLayout.LayoutParams locParams = new FrameLayout.LayoutParams(dp2px(50), dp2px(50)); - locParams.setMargins(0, 0, dp2px(20), dp2px(120)); + FrameLayout.LayoutParams locParams = new FrameLayout.LayoutParams(dp2px(44), dp2px(44)); + locParams.setMargins(0, 0, dp2px(15), dp2px(250)); // 调高一点,避开底部的面板 locParams.gravity = Gravity.BOTTOM | Gravity.END; container.addView(locBtn, locParams); } - private EditText createInput(Context context, String hint) { - EditText et = new EditText(context); - et.setHint(hint); - et.setTextSize(14f); - et.setTextColor(Color.BLACK); - et.setPadding(dp2px(12), dp2px(10), dp2px(12), dp2px(10)); - et.setBackground(getRoundedDrawable(Color.parseColor("#F5F5F5"), 6)); - et.setSingleLine(true); - et.setImeOptions(EditorInfo.IME_ACTION_DONE); - et.setFocusable(true); - et.setFocusableInTouchMode(true); - return et; + private LinearLayout createDetailPanel(Context context) { + LinearLayout panel = new LinearLayout(context); + panel.setOrientation(LinearLayout.VERTICAL); + panel.setBackground(getRoundedDrawable(Color.WHITE, 16)); + panel.setPadding(dp2px(20), dp2px(20), dp2px(20), dp2px(20)); + panel.setElevation(dp2px(12)); + + tvStationName = new TextView(context); + tvStationName.setTextSize(18); + tvStationName.setTextColor(Color.BLACK); + tvStationName.setTypeface(Typeface.DEFAULT_BOLD); + panel.addView(tvStationName); + + tvStationAddr = new TextView(context); + tvStationAddr.setTextSize(13); + tvStationAddr.setPadding(0, dp2px(4), 0, dp2px(10)); + tvStationAddr.setTextColor(Color.GRAY); + panel.addView(tvStationAddr); + + tvRouteInfo = new TextView(context); + tvRouteInfo.setTextSize(14); + tvRouteInfo.setTextColor(Color.parseColor("#333333")); + panel.addView(tvRouteInfo); + + Button startNaviBtn = new Button(context); + startNaviBtn.setText("开始导航"); + startNaviBtn.setTextColor(Color.WHITE); + startNaviBtn.setBackground(getRoundedDrawable(Color.parseColor("#017143"), 10)); + startNaviBtn.setOnClickListener(v -> startRouteSearch()); + + LinearLayout.LayoutParams btnParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp2px(48)); + btnParams.topMargin = dp2px(15); + panel.addView(startNaviBtn, btnParams); + + return panel; + } + + private void calculateRouteBeforeNavi() { + if (startPoint == null) { + Toast.makeText(mContext, "正在定位...", Toast.LENGTH_SHORT).show(); + return; + } + + if (endPoint == null) { + Toast.makeText(mContext, "请先选择目的地", Toast.LENGTH_SHORT).show(); + return; + } + + // 开始规划前隐藏输入框面板 + 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); + } + + @Override + public void onGetInputtips(List tipList, int rCode) { + if (rCode == 1000 && tipList != null && !tipList.isEmpty()) { + Tip tip = tipList.get(0); + if (tip.getPoint() != null) { + endPoint = new LatLng(tip.getPoint().getLatitude(), tip.getPoint().getLongitude()); + endName = tip.getName(); + } + } + } + + @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); + tvStationName.setText(endName); + tvStationAddr.setText(endInput.getText().toString()); + + String info = String.format("预计时间:%d分钟 | 行驶里程:%.1f公里 | 预计路费:%.0f元", + path.getDuration() / 60, path.getDistance() / 1000f, path.getTolls()); + tvRouteInfo.setText(info); + + aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(endPoint, 13f)); + } else { + // 规划失败回退面板 + searchArea.setVisibility(View.VISIBLE); + Toast.makeText(mContext, "路径规划失败: " + rCode, Toast.LENGTH_SHORT).show(); + } + } + + private void startRouteSearch() { + if (mActivity == null || startPoint == null || endPoint == null) return; + + Poi start = new Poi(startName, startPoint, ""); + Poi end = new Poi(endName, endPoint, ""); + AmapNaviParams params = new AmapNaviParams(start, null, end, AmapNaviType.DRIVER, AmapPageType.ROUTE); + + try { + AMapNavi mAMapNavi = AMapNavi.getInstance(mContext); + AMapCarInfo carInfo = new AMapCarInfo(); + carInfo.setCarNumber("沪AGK2267"); + carInfo.setCarType("1"); + mAMapNavi.setCarInfo(carInfo); + } catch (Exception e) { e.printStackTrace(); } + + AmapNaviPage.getInstance().showRouteActivity(mActivity, params, null); + } + + private void setupMapUi() { + aMap.setLocationSource(this); + aMap.setMyLocationEnabled(true); + aMap.setOnMarkerClickListener(this); + + MyLocationStyle myLocationStyle = new MyLocationStyle(); + try { + Bitmap carBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.car); + if (carBitmap != null) { + Bitmap scaledBitmap = Bitmap.createScaledBitmap(carBitmap, dp2px(30), dp2px(30), true); + myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromBitmap(scaledBitmap)); + } + } catch (Exception e) { e.printStackTrace(); } + + myLocationStyle.anchor(0.5f, 0.5f); + myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER); + aMap.setMyLocationStyle(myLocationStyle); + aMap.getUiSettings().setZoomControlsEnabled(false); + aMap.getUiSettings().setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_LEFT); } private GradientDrawable getRoundedDrawable(int color, int radiusDp) { @@ -239,55 +369,9 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, mContext.getResources().getDisplayMetrics()); } - private void setupMapUi() { - aMap.setLocationSource(this); - aMap.setMyLocationEnabled(true); - aMap.setOnMarkerClickListener(this); - - MyLocationStyle myLocationStyle = new MyLocationStyle(); - - // --- 放大定位图标 --- - try { - Bitmap carBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.car); - if (carBitmap != null) { - // 放大到 80dp - int iconSize = dp2px(25); - Bitmap scaledBitmap = Bitmap.createScaledBitmap(carBitmap, iconSize, iconSize, true); - myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromBitmap(scaledBitmap)); - } - } catch (Exception e) { - Log.e(TAG, "设置大图标失败", e); - } - - myLocationStyle.anchor(0.5f, 0.5f); - myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER); - myLocationStyle.showMyLocation(true); - myLocationStyle.strokeColor(Color.TRANSPARENT); - myLocationStyle.radiusFillColor(Color.TRANSPARENT); - aMap.setMyLocationStyle(myLocationStyle); - - aMap.getUiSettings().setZoomControlsEnabled(true); - aMap.getUiSettings().setScaleControlsEnabled(true); - aMap.getUiSettings().setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_LEFT); - } - - // ==================== LocationSource 接口实现 ==================== - @Override - public void activate(OnLocationChangedListener listener) { - mListener = listener; - startLocation(); - } - - @Override - public void deactivate() { - mListener = null; - if (mlocationClient != null) { - mlocationClient.stopLocation(); - mlocationClient.onDestroy(); - } - mlocationClient = null; - } - + @Override public void activate(OnLocationChangedListener listener) { mListener = listener; startLocation(); } + @Override public void deactivate() { mListener = null; if (mlocationClient != null) mlocationClient.stopLocation(); } + public void startLocation() { if (mlocationClient == null) { try { @@ -297,135 +381,49 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); mlocationClient.setLocationOption(option); mlocationClient.startLocation(); - Log.d(TAG, "定位启动成功"); - } catch (Exception e) { - Log.e(TAG, "定位启动失败", e); - } + } catch (Exception e) { e.printStackTrace(); } } } @Override public void onLocationChanged(AMapLocation loc) { - if (loc != null) { - if (mListener != null) { - mListener.onLocationChanged(loc); - } + if (loc != null && loc.getErrorCode() == 0) { currentLatLng = new LatLng(loc.getLatitude(), loc.getLongitude()); - - if (loc.getErrorCode() == 0) { - if (isFirstLocation) { - isFirstLocation = false; - startPoint = currentLatLng; - aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 14f)); - getAddressByLatlng(currentLatLng); - fetchRecommendStation(loc); - fetchNearbyStations(loc); - } + if (mListener != null) mListener.onLocationChanged(loc); + if (isFirstLocation) { + isFirstLocation = false; + startPoint = currentLatLng; + aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 14f)); + getAddressByLatlng(currentLatLng); + fetchRecommendStation(loc); + fetchNearbyStations(loc); } } } - // ==================== 逆地理编码 ==================== private void getAddressByLatlng(LatLng latLng) { - LatLonPoint point = new LatLonPoint(latLng.latitude, latLng.longitude); - RegeocodeQuery query = new RegeocodeQuery(point, 200, GeocodeSearch.AMAP); - geocoderSearch.getFromLocationAsyn(query); + geocoderSearch.getFromLocationAsyn(new RegeocodeQuery(new LatLonPoint(latLng.latitude, latLng.longitude), 200, GeocodeSearch.AMAP)); } @Override public void onRegeocodeSearched(RegeocodeResult result, int rCode) { - if (rCode == AMapException.CODE_AMAP_SUCCESS && result != null && result.getRegeocodeAddress() != null) { + if (rCode == 1000 && result != null) { RegeocodeAddress addr = result.getRegeocodeAddress(); - String fullAddr = addr.getFormatAddress(); - - // 优化地址显示逻辑 - startName = formatAddress(fullAddr,result); - - new Handler(Looper.getMainLooper()).post(() -> { - startInput.setText(startName); - startInput.setSelection(startName.length()); // 光标移到末尾 - }); - - Log.d(TAG, "逆地理编码成功: " + startName); - } else { - Log.e(TAG, "逆地理编码失败: code=" + rCode + ", result=" + (result != null ? "null" : "has data")); + startName = addr.getStreetNumber() != null ? addr.getStreetNumber().getStreet() : addr.getDistrict(); } } - /** - * 格式化地址显示,移除重复的前缀并限制长度 - */ - private String formatAddress(String fullAddress,RegeocodeResult result) { - if (fullAddress == null || fullAddress.isEmpty()) { - return "未知地点"; - } - - // 获取各级地址信息 - String province = null; - String city = null; - String district = null; - String township = null; - - try { - if (result.getRegeocodeAddress() != null) { - RegeocodeAddress addr = result.getRegeocodeAddress(); - province = addr.getProvince(); - city = addr.getCity(); - district = addr.getDistrict(); - township = addr.getTownship(); - } - } catch (Exception e) { - Log.e(TAG, "获取地址信息失败", e); - } - - String formattedAddr = fullAddress; - - // 按优先级移除重复前缀(省、市、区、乡) - String[] prefixes = {province, city, district, township}; - for (String prefix : prefixes) { - if (prefix != null && !prefix.isEmpty() && formattedAddr.startsWith(prefix)) { - formattedAddr = formattedAddr.substring(prefix.length()); - Log.d(TAG, "移除前缀: " + prefix + " -> " + formattedAddr); - } - } - - // 限制地址长度并添加省略号 - if (formattedAddr.length() > 25) { - formattedAddr = formattedAddr.substring(0, 25) + "..."; - Log.d(TAG, "地址长度截断: " + formattedAddr); - } - - return formattedAddr; - } - - @Override - public void onGeocodeSearched(GeocodeResult result, int rCode) { - } - - // ==================== API请求 ==================== - private void fetchRecommendStation(AMapLocation loc) { try { JSONObject json = new JSONObject(); - json.put("province", loc.getProvince() != null ? loc.getProvince() : ""); - json.put("city", loc.getCity() != null && !loc.getCity().isEmpty() ? loc.getCity() : ""); - json.put("district", loc.getDistrict() != null ? loc.getDistrict() : ""); - json.put("longitude", String.valueOf(loc.getLongitude())); - json.put("latitude", String.valueOf(loc.getLatitude())); + json.put("province", loc.getProvince()); + json.put("city", loc.getCity().isEmpty() ? loc.getProvince() : loc.getCity()); + json.put("longitude", loc.getLongitude()); + json.put("latitude", loc.getLatitude()); - RequestBody body = RequestBody.create(json.toString(), MediaType.parse("application/json; charset=utf-8")); - Request request = new Request.Builder() - .url("https://beta-esg.api.lnh2e.com/appointment/station/getStationInfoByArea") - .post(body) - .build(); - - httpClient.newCall(request).enqueue(new Callback() { - @Override - public void onFailure(@NonNull Call call, @NonNull IOException e) { - } - - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { + httpClient.newCall(new Request.Builder().url("https://beta-esg.api.lnh2e.com/appointment/station/getStationInfoByArea").post(RequestBody.create(json.toString(), MediaType.parse("application/json"))).build()).enqueue(new Callback() { + @Override public void onFailure(@NonNull Call call, @NonNull IOException e) {} + @Override public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { if (response.isSuccessful() && response.body() != null) { try { JSONObject res = new JSONObject(response.body().string()); @@ -439,68 +437,43 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation markStation(endPoint, endName, true); }); } - } catch (Exception e) { - e.printStackTrace(); - } + } catch (Exception e) { e.printStackTrace(); } } } }); - } catch (Exception e) { - e.printStackTrace(); - } + } catch (Exception e) { e.printStackTrace(); } } private void fetchNearbyStations(AMapLocation loc) { try { JSONObject json = new JSONObject(); - json.put("longitude", String.valueOf(loc.getLongitude())); - json.put("latitude", String.valueOf(loc.getLatitude())); + json.put("longitude", loc.getLongitude()); + json.put("latitude", loc.getLatitude()); - RequestBody body = RequestBody.create(json.toString(), MediaType.parse("application/json; charset=utf-8")); - Request request = new Request.Builder() - .url("https://beta-esg.api.lnh2e.com/appointment/station/getNearbyHydrogenStationsByLocation") - .post(body) - .build(); - - httpClient.newCall(request).enqueue(new Callback() { - @Override - public void onFailure(@NonNull Call call, @NonNull IOException e) { - } - - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { + httpClient.newCall(new Request.Builder().url("https://beta-esg.api.lnh2e.com/appointment/station/getNearbyHydrogenStationsByLocation").post(RequestBody.create(json.toString(), MediaType.parse("application/json"))).build()).enqueue(new Callback() { + @Override public void onFailure(@NonNull Call call, @NonNull IOException e) {} + @Override public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { if (response.isSuccessful() && response.body() != null) { try { JSONObject res = new JSONObject(response.body().string()); - if (res.getInt("code") == 0 && !res.isNull("data")) { - JSONArray array = res.getJSONArray("data"); - new Handler(Looper.getMainLooper()).post(() -> { - for (int i = 0; i < array.length(); i++) { - try { - JSONObject item = array.getJSONObject(i); - markStation(new LatLng(item.getDouble("latitude"), item.getDouble("longitude")), - item.getString("name"), false); - } catch (Exception ignored) { - } - } - }); - } - } catch (Exception e) { - e.printStackTrace(); - } + JSONArray array = res.getJSONArray("data"); + new Handler(Looper.getMainLooper()).post(() -> { + for (int i = 0; i < array.length(); i++) { + try { + JSONObject item = array.getJSONObject(i); + markStation(new LatLng(item.getDouble("latitude"), item.getDouble("longitude")), item.getString("name"), false); + } catch (Exception ignored) {} + } + }); + } catch (Exception e) { e.printStackTrace(); } } } }); - } catch (Exception e) { - e.printStackTrace(); - } + } catch (Exception e) { e.printStackTrace(); } } private void markStation(LatLng latLng, String name, boolean isRecommend) { - MarkerOptions opt = new MarkerOptions() - .position(latLng).title(name) - .icon(BitmapDescriptorFactory.defaultMarker(isRecommend ? BitmapDescriptorFactory.HUE_RED : BitmapDescriptorFactory.HUE_GREEN)); - Marker m = aMap.addMarker(opt); + Marker m = aMap.addMarker(new MarkerOptions().position(latLng).title(name).icon(BitmapDescriptorFactory.defaultMarker(isRecommend ? BitmapDescriptorFactory.HUE_RED : BitmapDescriptorFactory.HUE_GREEN))); m.setObject(latLng); stationMarkers.add(m); } @@ -511,185 +484,28 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation endPoint = (LatLng) marker.getObject(); endName = marker.getTitle(); endInput.setText(endName); - startRouteSearch(); + calculateRouteBeforeNavi(); } return true; } - // ==================== 路径规划 ==================== - - private void startRouteSearch() { - if (startPoint == null || endPoint == null) { - Toast.makeText(mContext, "正在定位中,请稍后...", Toast.LENGTH_SHORT).show(); - return; - } - - Poi start = new Poi(startName, startPoint, ""); - Poi end = new Poi(endName, endPoint, ""); - - AmapNaviParams params = new AmapNaviParams(start, null, end, AmapNaviType.DRIVER, AmapPageType.ROUTE); - - try { - AMapNavi mAMapNavi = AMapNavi.getInstance(mContext); - AMapCarInfo carInfo = new AMapCarInfo(); - carInfo.setCarNumber("沪AGK2267"); - carInfo.setCarType("1"); - carInfo.setVehicleAxis("6"); - carInfo.setVehicleHeight("3.32"); - carInfo.setVehicleLength("6.9"); - carInfo.setVehicleWidth("2.26"); - carInfo.setVehicleSize("2"); - carInfo.setVehicleLoad("4.5"); - carInfo.setVehicleWeight("4.5"); - carInfo.setRestriction(true); - carInfo.setVehicleLoadSwitch(true); - mAMapNavi.setCarInfo(carInfo); - } catch (com.amap.api.maps.AMapException e) { - Log.e(TAG, "设置车辆信息失败", e); - } - - params.setRouteStrategy(PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_DEFAULT); - - if (mActivity != null) { - AmapNaviPage.getInstance().showRouteActivity(mActivity, params, new INaviInfoCallback() { - @Override - public void onInitNaviFailure() { - Log.e(TAG, "导航初始化失败"); - } - - @Override - public void onGetNavigationText(String s) { - } - - @Override - public void onLocationChange(AMapNaviLocation location) { - } - - @Override - public void onArriveDestination(boolean b) { - } - - @Override - public void onStartNavi(int i) { - } - - @Override - public void onCalculateRouteSuccess(int[] ints) { - } - - @Override - public void onCalculateRouteFailure(int i) { - } - - @Override - public void onStopSpeaking() { - } - - @Override - public void onReCalculateRoute(int i) { - - } - - @Override - public void onArrivedWayPoint(int i) { - } - - @Override - public void onExitPage(int i) { - } - - @Override - public void onStrategyChanged(int i) { - } - - @Override - public void onMapTypeChanged(int i) { - } - - @Override - public void onNaviDirectionChanged(int i) { - } - - @Override - public void onDayAndNightModeChanged(int i) { - } - - @Override - public void onBroadcastModeChanged(int i) { - } - - @Override - public void onScaleAutoChanged(boolean b) { - } - - @Override - public View getCustomNaviBottomView() { - return null; - } - - @Override - public View getCustomNaviView() { - return null; - } - - @Override - public View getCustomMiddleView() { - return null; - } - }); - } - } - - @Override - public void onDriveRouteSearched(DriveRouteResult result, int rCode) { - } - - @Override - public void onBusRouteSearched(BusRouteResult r, int c) { - } - - @Override - public void onWalkRouteSearched(WalkRouteResult r, int c) { - } - - @Override - public void onRideRouteSearched(RideRouteResult r, int c) { - } + @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) { - Context base = ((android.content.ContextWrapper) context).getBaseContext(); - if (base instanceof Activity) - return (Activity) base; - } + 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(); - } + 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(); } } diff --git a/ln_jq_app/ios/Podfile.lock b/ln_jq_app/ios/Podfile.lock index 8b5621d..f26e170 100644 --- a/ln_jq_app/ios/Podfile.lock +++ b/ln_jq_app/ios/Podfile.lock @@ -49,6 +49,9 @@ PODS: - OrderedSet (6.0.3) - package_info_plus (0.4.5): - Flutter + - path_provider_foundation (0.0.1): + - Flutter + - FlutterMacOS - permission_handler_apple (9.3.0): - Flutter - shared_preferences_foundation (0.0.1): @@ -70,6 +73,7 @@ DEPENDENCIES: - image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`) - mobile_scanner (from `.symlinks/plugins/mobile_scanner/darwin`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) + - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) @@ -114,6 +118,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/mobile_scanner/darwin" package_info_plus: :path: ".symlinks/plugins/package_info_plus/ios" + path_provider_foundation: + :path: ".symlinks/plugins/path_provider_foundation/darwin" permission_handler_apple: :path: ".symlinks/plugins/permission_handler_apple/ios" shared_preferences_foundation: @@ -125,28 +131,29 @@ SPEC CHECKSUMS: AlicloudELS: fbf821383330465a5af84a033f36f263ae46ca41 AlicloudPush: 52cbf38ffc20c07f039cbc72d5738745fd986215 AlicloudUTDID: 5d2f22d50e11eecd38f30bc7a48c71925ea90976 - aliyun_push_flutter: ab0bf7112ef3797f506770a7a9f47f004635a9f6 + aliyun_push_flutter: 0fc2f048a08687ef256c0cfdd72dd7a550ef3347 AMapFoundation-NO-IDFA: 6ce0ef596d4eb8d934ff498e56747b6de1247b05 AMapLocation-NO-IDFA: 590fd42af0c8ea9eac26978348221bbc16be4ef9 AMapNavi-NO-IDFA: 22edfa7d6a81d75c91756e31b6c26b7746152233 - AMapNavIOSSDK: 0cd6ec22ab6b6aba268028a5b580e18bb8066f7e + AMapNavIOSSDK: ca325c9ac3378daea6a6be4bd8c34fe48d3ac896 AMapSearch-NO-IDFA: 53b2193244be8f07f3be0a4d5161200236960587 - connectivity_plus: 2a701ffec2c0ae28a48cf7540e279787e77c447d - device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d + connectivity_plus: cb623214f4e1f6ef8fe7403d580fdad517d2f7dd + device_info_plus: 71ffc6ab7634ade6267c7a93088ed7e4f74e5896 Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467 - flutter_inappwebview_ios: 6f63631e2c62a7c350263b13fa5427aedefe81d4 - flutter_native_splash: df59bb2e1421aa0282cb2e95618af4dcb0c56c29 - flutter_pdfview: 2e4d13ffb774858562ffbdfdb61b40744b191adc - geolocator_apple: 66b711889fd333205763b83c9dcf0a57a28c7afd - image_picker_ios: 4f2f91b01abdb52842a8e277617df877e40f905b + flutter_inappwebview_ios: b89ba3482b96fb25e00c967aae065701b66e9b99 + flutter_native_splash: c32d145d68aeda5502d5f543ee38c192065986cf + flutter_pdfview: 32bf27bda6fd85b9dd2c09628a824df5081246cf + geolocator_apple: ab36aa0e8b7d7a2d7639b3b4e48308394e8cef5e + image_picker_ios: e0ece4aa2a75771a7de3fa735d26d90817041326 Masonry: 678fab65091a9290e40e2832a55e7ab731aad201 MJExtension: e97d164cb411aa9795cf576093a1fa208b4a8dd8 - mobile_scanner: 77265f3dc8d580810e91849d4a0811a90467ed5e + mobile_scanner: 9157936403f5a0644ca3779a38ff8404c5434a93 OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94 - package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4 - permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2 - shared_preferences_foundation: 5086985c1d43c5ba4d5e69a4e8083a389e2909e6 - url_launcher_ios: bb13df5870e8c4234ca12609d04010a21be43dfa + package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499 + path_provider_foundation: bb55f6dbba17d0dccd6737fe6f7f34fbd0376880 + permission_handler_apple: 4ed2196e43d0651e8ff7ca3483a069d469701f2d + shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb + url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1b PODFILE CHECKSUM: 97188da9dab9d4b3372eb4c16e872fbd555fdbea diff --git a/ln_jq_app/ios/Runner.xcodeproj/project.pbxproj b/ln_jq_app/ios/Runner.xcodeproj/project.pbxproj index 55acb81..6ed39fa 100644 --- a/ln_jq_app/ios/Runner.xcodeproj/project.pbxproj +++ b/ln_jq_app/ios/Runner.xcodeproj/project.pbxproj @@ -477,8 +477,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = 2228B9MS38; ENABLE_BITCODE = NO; @@ -742,8 +741,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = 2228B9MS38; ENABLE_BITCODE = NO; @@ -844,8 +842,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = 2228B9MS38; ENABLE_BITCODE = NO; diff --git a/ln_jq_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/ln_jq_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index e3773d4..b213f83 100644 --- a/ln_jq_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/ln_jq_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -61,6 +61,7 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" + enableGPUFrameCaptureMode = "3" enableGPUValidationMode = "1" allowLocationSimulation = "YES"> aps-environment development + com.apple.developer.background-tasks.continued-processing.gpu + + com.apple.developer.location.push + diff --git a/ln_jq_app/lib/common/styles/theme.dart b/ln_jq_app/lib/common/styles/theme.dart index d925319..4406085 100644 --- a/ln_jq_app/lib/common/styles/theme.dart +++ b/ln_jq_app/lib/common/styles/theme.dart @@ -12,7 +12,7 @@ class AppTheme { //http://192.168.110.222:8080/ //http://192.168.110.44:8080/ - static String test_service_url = "http://47.101.201.13:8443/api/"; + static String test_service_url = "https://beta-esg.api.lnh2e.com/"; static const String release_service_url = ""; //加氢站相关查询 diff --git a/ln_jq_app/lib/main.dart b/ln_jq_app/lib/main.dart index 8f0a668..1fafdc1 100644 --- a/ln_jq_app/lib/main.dart +++ b/ln_jq_app/lib/main.dart @@ -16,7 +16,7 @@ void main() async { WidgetsFlutterBinding.ensureInitialized(); WidgetsBinding widgetsBinding = await init( - isDebug: false, + isDebug: true, logTag: '小羚羚', supportedLocales: [const Locale('zh', 'CN')], ); @@ -34,7 +34,7 @@ void main() async { // 设计稿尺寸 单位:dp designSize: const Size(390, 844), // Getx Log - enableLog: false, + enableLog: true, // 默认的跳转动画 defaultTransition: Transition.rightToLeft, // 主题模式 @@ -77,7 +77,7 @@ void initHttpSet() { return null; } else if (baseModel.code == 401) { await StorageService.to.clearLoginInfo(); - // Get.offAll(() => const LoginPage()); + Get.offAll(() => const LoginPage()); return baseModel.message; } else { return (baseModel.error.toString()).isEmpty diff --git a/ln_jq_app/lib/pages/c_page/base_widgets/view.dart b/ln_jq_app/lib/pages/c_page/base_widgets/view.dart index 4e9db82..f525e37 100644 --- a/ln_jq_app/lib/pages/c_page/base_widgets/view.dart +++ b/ln_jq_app/lib/pages/c_page/base_widgets/view.dart @@ -1,10 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:get/get.dart'; import 'package:getx_scaffold/getx_scaffold.dart'; import 'package:ln_jq_app/common/login_util.dart'; import 'package:ln_jq_app/pages/c_page/base_widgets/NativePageIOS.dart'; import 'package:ln_jq_app/pages/c_page/car_info/view.dart'; -import 'package:ln_jq_app/pages/c_page/map/view.dart'; import 'package:ln_jq_app/pages/c_page/mine/view.dart'; import 'package:ln_jq_app/pages/c_page/reservation/view.dart'; diff --git a/ln_jq_app/lib/pages/home/controller.dart b/ln_jq_app/lib/pages/home/controller.dart index 4919c47..7c339cb 100644 --- a/ln_jq_app/lib/pages/home/controller.dart +++ b/ln_jq_app/lib/pages/home/controller.dart @@ -43,8 +43,7 @@ class HomeController extends GetxController with BaseControllerMixin { } } else { // 未登录,直接去登录页 - return BaseWidgetsPage(); - // return LoginPage(); + return LoginPage(); } }