优化搜索

This commit is contained in:
2026-03-27 13:23:10 +08:00
parent 587dd48896
commit 0123025296

View File

@@ -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<Marker> 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) {