Преглед на файлове

⚙ 移除高德,使用自建逆地址编码

快乐的梦鱼 преди 1 месец
родител
ревизия
227702dcf1
променени са 4 файла, в които са добавени 24 реда и са изтрити 36 реда
  1. 21 32
      src/api/map/MapApi.ts
  2. 1 1
      src/common/components/dynamicf/ComponentConfigs.ts
  3. 0 1
      src/common/config/ApiCofig.ts
  4. 2 2
      src/pages/dig/forms/data/spots.ts

+ 21 - 32
src/api/map/MapApi.ts

@@ -31,39 +31,28 @@ export class MapApi extends MapServerRequestModule<DataModel> {
     super();
   }
 
-
-  searchPoi(name: string, page = 1, size = 10, querys?: QueryParams) {
-    return this.get(`/v3/place/text?keywords=${encodeURIComponent(name)}&citylimit=true&offset=${size}&page=${page}`, `搜索POI ${name} 第${page}页`, {
-      ...querys,
-    })
-      .then(res => transformArrayDataModel(Poi, res.data ?? [], ''))
-      .catch(e => { throw e });
-  }
-  regeo(lat: number, lng: number, querys?: QueryParams) {
-    return this.get(`/v3/geocode/regeo`, `查询经纬度(${lat}, ${lng})所属区县`, {
-      location: `${lng},${lat}`,
-      ...querys,
-    })
-      .then(res => (res.data as any).regeocode.addressComponent as {
-        country: string,
-        province: string,
-        city: string,
-        district: string,
-        adcode: string,
-        township: string,
-        citycode: string,
-        towncode: string,
-      })
-      .catch(e => { throw e });
-  }
-  regeoAddress(lat: number, lng: number, querys?: QueryParams) {
-    return this.get(`/v3/geocode/regeo`, `查询经纬度(${lat}, ${lng})地址`, {
-      location: `${lng},${lat}`,
-      ...querys,
-    })
-      .then(res => (res.data as any).regeocode.formatted_address as string)
-      .catch(e => { throw e });
+  /**
+   * 逆地址编码,根据经纬度获取详细地址
+   * @param lat 纬度
+   * @param lng 经度
+   * @returns 详细地址
+   */
+  async regeo(lat: number, lng: number) {
+    const data = (await this.post<any>(`https://subserver.wenlvti.net/localgeo/localGeo/getGeo`, `逆地址编码`, {
+      lat: lat.toFixed(6), 
+      lng: lng.toFixed(6), 
+    }));
+    return data.raw as {
+      formatAddress: string,
+      province: string,
+      city: string,
+      district: string,
+      street: string,
+      adcode: string,
+      level: null
+    }
   }
+  
   loadCityData() {
     return new Promise((resolve, reject) => {
       uni.request({

+ 1 - 1
src/common/components/dynamicf/ComponentConfigs.ts

@@ -15,7 +15,7 @@ export default [
   {
     name: 'select-address',
     props: {
-      loadFormattedAddress: (latlon: [number, number]) => MapApi.regeoAddress(latlon[0], latlon[1]),
+      loadFormattedAddress: async (latlon: [number, number]) => (await MapApi.regeo(latlon[0], latlon[1])).formatAddress,
     },
   },
 ] as IDynamicFormComponentAdditionalDefine[];

+ 0 - 1
src/common/config/ApiCofig.ts

@@ -9,7 +9,6 @@ export default {
   },
   mainBodyId: 1,
   platformId: 330,
-  amapServerKey: '8fd09264c33678141f609588c432df0e',
   bugReport: {
     server: 'https://update-server1.imengyu.top/bug-submit',
     appId: 1,

+ 2 - 2
src/pages/dig/forms/data/spots.ts

@@ -28,8 +28,8 @@ export const villageInfoSpotsFormItems : SingleForm = [CommonInfoModel, (form) =
             onChange(val: [number, number]) {
               if (form.value.getValueByPath('address'))
                 return;
-              MapApi.regeoAddress(val[0], val[1]).then(res => {
-                form.value.setValueByPath('address', res);
+              MapApi.regeo(val[0], val[1]).then(res => {
+                form.value.setValueByPath('address', res.formatAddress);
               });
             },
           },