hejianhao
2026-03-18 52c84dc7402161714dd67c5989f6d3d9a4835b3e
fix(robotaxi): 修复地图定位回跳和城市匹配问题

- 修正地图返回当前位置时的缩放逻辑,防止地图位置跳回
- 增强城市信息匹配机制,支持模糊匹配并确保获取正确的城市ID
- 在订单创建前添加城市ID校验,避免因城市信息缺失导致下单失败
- 调整温度调节步长为0.5℃,并优化显示格式
- 更新埋点数据源ID并添加站点搜索埋点
6个文件已修改
97 ■■■■■ 已修改文件
config/dev.js 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/robotaxi/home/index.tsx 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robotaxi/pages/begin-route/components/calling-car.tsx 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robotaxi/pages/begin-route/index.tsx 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robotaxi/pages/site-search/index.tsx 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/Robotaxi-public-method.ts 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
config/dev.js
@@ -39,7 +39,7 @@
const GIO_CONFIG = {
  accountId: '"89a922449121f7c2"', // 埋点平台id
  dataSourceId: {
    weapp: '"9abffa1fe7a0b35e"', // 埋点数据源id
    weapp: '"aac18af1a631d28f"', // 埋点数据源id
  },
  host: '"https://collect.test.xiaopeng.com"',
}
src/pages/robotaxi/home/index.tsx
@@ -663,11 +663,15 @@
    if (isLocationAuthDenied) return;
    shouldIgnoreRegionChange.current = false;
    isReturningToOrigin.current = true;
    setMapScale(14);
    // 强制触发缩放更新:如果当前是16,则设置为16.000001以触发props变化
    setMapScale(prev => Math.abs(prev - 16) < 0.001 ? 16.000001 : 16);
    const mapCtx = Taro.createMapContext('map');
    mapCtx.moveToLocation();
    try {
      const loc = await Taro.getLocation({ type: 'gcj02' });
      // 同步位置状态,防止因缩放导致地图跳回旧位置
      setLatitude(loc.latitude);
      setLongitude(loc.longitude);
      const data = await getAddressByLocation(loc.longitude, loc.latitude);
      const addressComponent = data?.regeocodeData?.addressComponent;
      if (!addressComponent) {
src/robotaxi/pages/begin-route/components/calling-car.tsx
@@ -576,13 +576,13 @@
                                    <Image
                                        className="car-card-temp-content-img"
                                        src={require('../../../assets/T-down.png')}
                                        onClick={typeof tempStatus === 'number' && tempStatus > TEMP_MIN ? () => handleTempChange(-1) : undefined}
                                        onClick={typeof tempStatus === 'number' && tempStatus > TEMP_MIN ? () => handleTempChange(-0.5) : undefined}
                                    />
                                    <View className="car-card-temp-content-text">{tempStatus}℃</View>
                                    <View className="car-card-temp-content-text">{typeof tempStatus === 'number' ? tempStatus.toFixed(1) : '--'}℃</View>
                                    <Image
                                        className="car-card-temp-content-img"
                                        src={require('../../../assets/T-up.png')}
                                        onClick={typeof tempStatus === 'number' && tempStatus < TEMP_MAX ? () => handleTempChange(1) : undefined}
                                        onClick={typeof tempStatus === 'number' && tempStatus < TEMP_MAX ? () => handleTempChange(0.5) : undefined}
                                    />
                                </View>
                            </View>
src/robotaxi/pages/begin-route/index.tsx
@@ -1527,7 +1527,39 @@
      }
    }
    const selectedCity = Taro.getStorageSync('selectedCity');
    const openCityId = selectedCity?.id || 0;
    let openCityId = selectedCity?.id || 0;
    // 如果缓存中没有城市ID,尝试通过定位重新匹配一次
    if (!openCityId) {
      try {
        const loc = await Taro.getLocation({ type: 'gcj02' });
        const data = await getAddressByLocation(loc.longitude, loc.latitude);
        const addressComponent = data?.regeocodeData?.addressComponent;
        if (addressComponent) {
          const { city, province, adcode } = addressComponent;
          const cityName = (city && typeof city === 'string' && city.length > 0) ? city : province;
          const cityCode = convertAdcodeToCityCode(adcode, cityName, province);
          const cityInfo = await getCityInfoWithId(cityCode, cityName);
          if (cityInfo?.id) {
            openCityId = cityInfo.id;
            Taro.setStorageSync('selectedCity', cityInfo);
          }
        }
      } catch (e) {
        console.error('Failed to fetch city info before order:', e);
      }
    }
    // 如果还是拿不到城市ID,拦截下单
    if (!openCityId) {
      Taro.showToast({
        title: '未能获取所在城市信息,请重试',
        icon: 'none',
      });
      setCallSubmitting(false);
      return;
    }
    const waitingTime = Number(fareEstimate?.waitingTime || 0);
    const estimatedTime = formatDateTime(new Date(Date.now() + waitingTime * 60 * 1000));
    const cachedCouponId = Taro.getStorageSync('selectedCouponId');
src/robotaxi/pages/site-search/index.tsx
@@ -8,9 +8,9 @@
import { getStartPoints, getEndPoints, queryPointByName } from '../../api/site-search';
import { formatDistance, debounce, getDistance } from '../../../utils/Robotaxi-public-method';
import { getOrderDistance } from '../../api/select-map-site';
import { AMAP_KEY } from '../../../constants/api';
import { AMAP_KEY, _UID } from '../../../constants/api';
import amapFile from '../../../libs/amap-wx.130.js';
import { checkOtp } from '../../../utils/tools';
import { checkOtp, getStorage } from '../../../utils/tools';
import TipPopup from '../select-map-site/components/tip-popup';
import { getNearestSite } from '../../api/home';
@@ -242,6 +242,18 @@
          return;
        }
      } catch { }
      // 埋点
      getStorage(_UID).then((uid) => {
        const $app: any = Taro.getApp().$app;
        $app.xpReportSend({
          eventId: 'RT_mp_user_address_searched',
          para: {
            user_id: uid || '-1',
            search_type: pageType === 'start' ? 'pickup ' : 'dropoff ',
          },
        });
        console.log('选择起点站点埋点成功', 'RT_mp_user_address_searched', 'user_id' + uid, 'search_type' + (pageType === 'start' ? 'pickup ' : 'dropoff '));
      });
      Taro.setStorageSync('startSite', item);
      Taro.navigateBack()
    } else if (pageType == 'end') {
@@ -278,6 +290,18 @@
          }
        }
      } catch { }
      // 埋点
      getStorage(_UID).then((uid) => {
        const $app: any = Taro.getApp().$app;
        $app.xpReportSend({
          eventId: 'RT_mp_user_address_searched',
          para: {
            user_id: uid || '-1',
            search_type: pageType === 'start' ? 'pickup ' : 'dropoff ',
          },
        });
      });
      console.log('选择终点站点埋点成功', 'RT_mp_user_address_searched', 'user_id' + uid, 'search_type' + (pageType === 'start' ? 'pickup ' : 'dropoff '));
      Taro.setStorageSync('endSite', item)
      Taro.reLaunch({
        url: Taro.getStorageSync('orderId') ? '/robotaxi/pages/begin-route/index?skipPageFlag=1' : '/robotaxi/pages/begin-route/index',
src/utils/Robotaxi-public-method.ts
@@ -359,10 +359,25 @@
    let cityId = 0;
    if (Array.isArray(res.cities)) {
      const target = res.cities.find(item => item.adcode === cityCode);
      if (target) {
        cityId = target.id;
      // 优先匹配 adcode
      let target = res.cities.find(item => item.adcode === cityCode);
      // 如果 adcode 匹配失败,尝试匹配 cityName
      if (!target && cityName) {
        // 移除"市"字进行模糊匹配,增加匹配成功率
        const normalizedCityName = cityName.replace(/市$/, '');
        target = res.cities.find(item => {
          const itemName = item.name.replace(/市$/, '');
          return itemName === normalizedCityName || item.name.includes(normalizedCityName) || normalizedCityName.includes(item.name);
        });
      }
      if (target) {
      cityId = target.id;
      // 修正返回的 code,确保使用的是系统匹配到的城市的标准 adcode
      if (target.adcode) {
        cityCode = target.adcode;
      }
    }
    }
    return {
      name: cityName,