From 01230252969ddc735f538c6d13da10382106bb72 Mon Sep 17 00:00:00 2001 From: userGyl Date: Fri, 27 Mar 2026 13:23:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lnkj/ln_jq_app/NativeMapView.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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 3acfd12..720435a 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 @@ -137,6 +137,8 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation private LatLng startPoint; private LatLng endPoint; private boolean isFirstLocation = true; + private boolean isUserSelectedDestination = false; // 标识用户是否手动选择了目的地 + private boolean isProgrammaticTextChange = false; // 标识是否是程序自动设置文本 private final List stationMarkers = new ArrayList<>(); // 存储token和车牌号 @@ -268,7 +270,10 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation String name = tip.getName(); String district = tip.getDistrict(); endName = name; + isUserSelectedDestination = true; // 标识用户手动选择了目的地 + isProgrammaticTextChange = true; // 标识是程序自动设置文本 endInput.setText(district != null && !district.isEmpty() ? name + " " + district : name); + isProgrammaticTextChange = false; // 恢复标志 suggestionList.setVisibility(View.GONE); } }); @@ -280,6 +285,11 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation @Override public void onTextChanged(CharSequence s, int start, int before, int count) { + // 如果是程序自动设置文本,不触发搜索 + if (isProgrammaticTextChange) { + return; + } + if (s.length() > 1) { // 使用当前位置的城市进行搜索 String city = currentLatLng != null ? "" : ""; @@ -593,11 +603,16 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation } //确定目的地坐标和名称 - // 优先级:truckRouteData (接口返回的精准点) > endPoint (地图点击/搜索的点) + // 优先级:用户手动选择 > truckRouteData (接口返回的精准点) > endPoint (地图点击/搜索的点) LatLng finalDestinationLatLng = null; String finalDestinationName = endName; - if (truckRouteData != null && truckRouteData.destinationSite != null) { + // 如果用户手动选择了目的地,直接使用用户选择的地址 + if (isUserSelectedDestination && endPoint != null) { + finalDestinationLatLng = endPoint; + finalDestinationName = endName; + } else if (truckRouteData != null && truckRouteData.destinationSite != null) { + // 否则使用接口返回的推荐加氢站地址 String latStr = truckRouteData.destinationSite.latitude; String lngStr = truckRouteData.destinationSite.longitude; @@ -883,6 +898,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation endName = data.getString("name"); selectedSiteId = data.optString("id", ""); endAddress = data.optString("address", ""); + isUserSelectedDestination = false; // 系统推荐的地址,不是用户选择 new Handler(Looper.getMainLooper()).post(() -> { markStation(endPoint, endName, endAddress, selectedSiteId, true); }); @@ -994,6 +1010,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation // 更新 UI 和 业务逻辑 endName = marker.getTitle(); + isUserSelectedDestination = true; // 标识用户手动选择了目的地 // 需要传入当前位置以便接口计算路线 if (mlocationClient != null && mlocationClient.getLastKnownLocation() != null) {