@smart100/spu-web-plugin 1.0.24 → 1.0.25-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var version = "1.0.24";
1
+ var version = "1.0.25-beta.2";
2
2
 
3
3
  /** Detect free variable `global` from Node.js. */
4
4
  var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
@@ -17770,8 +17770,24 @@ var getLocationByNative = /*#__PURE__*/function () {
17770
17770
  var result = {
17771
17771
  longitude: res.longitude.toString(),
17772
17772
  latitude: res.latitude.toString(),
17773
- address: res.address || ''
17773
+ address: res.address || '',
17774
+ // poiname: res.poiname || '',
17775
+ regionid: res.regionid || '',
17776
+ country: res.country || '',
17777
+ province: res.province || '',
17778
+ city: res.city || '',
17779
+ district: res.district || '',
17780
+ street: res.street || '',
17781
+ number: res.number || '',
17782
+ detailaddr: res.detailaddr || ''
17783
+ // poiid: res.poiid || '',
17784
+ // poitypename: res.poitypename || '',
17785
+ // poitypecode: res.poitypecode || '',
17786
+ // phonenumber: res.phonenumber || '',
17787
+ // signboard: res.signboard || '',
17788
+ // maptype: res.maptype || '',
17774
17789
  };
17790
+
17775
17791
  console.log("getLocationByNative success: ".concat(JSON.stringify(result)));
17776
17792
  resolve(result);
17777
17793
  } else {
@@ -17868,10 +17884,54 @@ var getLocationByAMap = /*#__PURE__*/function () {
17868
17884
  lat = _res$position.lat;
17869
17885
  var result = {
17870
17886
  longitude: lng.toString(),
17871
- latitude: lat.toString()
17887
+ latitude: lat.toString(),
17888
+ address: '',
17889
+ // poiname: '',
17890
+ regionid: '',
17891
+ country: '',
17892
+ province: '',
17893
+ city: '',
17894
+ district: '',
17895
+ street: '',
17896
+ number: '',
17897
+ detailaddr: ''
17898
+ // poiid: '', // 图商的id
17899
+ // poitypename: '', // 图商的poi类型名称
17900
+ // poitypecode: '', // 图商的poi类型code
17901
+ // phonenumber: '',
17902
+ // signboard: '',
17903
+ // maptype: "amap"
17872
17904
  };
17873
- console.log("getLocationByAMap success: ".concat(JSON.stringify(result)));
17874
- resolve(result);
17905
+ // 通过经纬度获取详细地址信息
17906
+ getAddressDetailByAMap({
17907
+ longitude: lng.toString(),
17908
+ latitude: lat.toString()
17909
+ }).then(function (addrssDetail) {
17910
+ if (addrssDetail) {
17911
+ result.address = addrssDetail.addressDetail.address;
17912
+ // result.poiname = addrssDetail.addressDetail.poiname
17913
+ result.regionid = addrssDetail.addressDetail.regionid;
17914
+ result.country = addrssDetail.addressDetail.country;
17915
+ result.province = addrssDetail.addressDetail.province;
17916
+ result.city = addrssDetail.addressDetail.city;
17917
+ result.district = addrssDetail.addressDetail.district;
17918
+ result.street = addrssDetail.addressDetail.street;
17919
+ result.number = addrssDetail.addressDetail.number;
17920
+ result.detailaddr = addrssDetail.addressDetail.detailaddr;
17921
+ // result.poiid = addrssDetail.addressDetail.poiid
17922
+ // result.poitypename = addrssDetail.addressDetail.poitypename
17923
+ // result.poitypecode = addrssDetail.addressDetail.poitypecode
17924
+ // result.phonenumber = addrssDetail.addressDetail.phonenumber
17925
+ // result.signboard = addrssDetail.addressDetail.signboard
17926
+ }
17927
+
17928
+ console.log("getLocationByAMap success: ".concat(JSON.stringify(result)));
17929
+ resolve(result);
17930
+ })["catch"](function (err) {
17931
+ console.error(err);
17932
+ console.error('getLocationByAMap fail');
17933
+ resolve(null);
17934
+ });
17875
17935
  } else {
17876
17936
  console.error('getLocationByAMap fail');
17877
17937
  resolve(null);
@@ -17913,10 +17973,56 @@ var getCityLocationByAMap = /*#__PURE__*/function () {
17913
17973
  var lat = res.position[1].toString();
17914
17974
  var result = {
17915
17975
  longitude: lng.toString(),
17916
- latitude: lat.toString()
17976
+ latitude: lat.toString(),
17977
+ address: '',
17978
+ // poiname: '',
17979
+ regionid: '',
17980
+ country: '',
17981
+ province: '',
17982
+ city: '',
17983
+ district: '',
17984
+ street: '',
17985
+ number: '',
17986
+ detailaddr: ''
17987
+ // poiid: '', // 图商的id
17988
+ // poitypename: '', // 图商的poi类型名称
17989
+ // poitypecode: '', // 图商的poi类型code
17990
+ // phonenumber: '',
17991
+ // signboard: '',
17992
+ // maptype: "amap"
17917
17993
  };
17994
+
17918
17995
  console.log("getCityLocationByAMap success: ".concat(JSON.stringify(result)));
17919
- resolve(result);
17996
+ // 通过经纬度获取详细地址信息
17997
+ getAddressDetailByAMap({
17998
+ longitude: lng.toString(),
17999
+ latitude: lat.toString()
18000
+ }).then(function (addrssDetail) {
18001
+ if (addrssDetail) {
18002
+ result.address = addrssDetail.addressDetail.address;
18003
+ // result.poiname = addrssDetail.addressDetail.poiname
18004
+ result.regionid = addrssDetail.addressDetail.regionid;
18005
+ result.country = addrssDetail.addressDetail.country;
18006
+ result.province = addrssDetail.addressDetail.province;
18007
+ result.city = addrssDetail.addressDetail.city;
18008
+ result.district = addrssDetail.addressDetail.district;
18009
+ result.street = addrssDetail.addressDetail.street;
18010
+ result.number = addrssDetail.addressDetail.number;
18011
+ result.detailaddr = addrssDetail.addressDetail.detailaddr;
18012
+ // result.poiid = addrssDetail.addressDetail.poiid
18013
+ // result.poitypename = addrssDetail.addressDetail.poitypename
18014
+ // result.poitypecode = addrssDetail.addressDetail.poitypecode
18015
+ // result.phonenumber = addrssDetail.addressDetail.phonenumber
18016
+ // result.signboard = addrssDetail.addressDetail.signboard
18017
+ }
18018
+
18019
+ console.log("getLocationByAMap success: ".concat(JSON.stringify(result)));
18020
+ resolve(result);
18021
+ })["catch"](function (err) {
18022
+ console.error(err);
18023
+ console.error('getLocationByAMap fail');
18024
+ resolve(null);
18025
+ });
17920
18026
  } else {
17921
18027
  console.error('getCityLocationByAMap fail');
17922
18028
  resolve(null);
@@ -17977,16 +18083,112 @@ var getAddressByAMap = /*#__PURE__*/function () {
17977
18083
  return _ref8.apply(this, arguments);
17978
18084
  };
17979
18085
  }();
17980
- // 腾讯ip定位:通过终端设备IP地址获取其当前所在地理位置,精确到市级,常用于显示当地城市天气预报、初始化用户城市等非精确定位场景。
17981
- var getIPLocationByTMap = /*#__PURE__*/function () {
17982
- var _ref9 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee9(ip) {
18086
+ // 高德逆地址解析详细数据
18087
+ var getAddressDetailByAMap = /*#__PURE__*/function () {
18088
+ var _ref9 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee9(position) {
17983
18089
  return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
17984
18090
  while (1) switch (_context9.prev = _context9.next) {
17985
18091
  case 0:
17986
- console.log('getIPLocationByTMap start...');
18092
+ console.log('getAddressDetailByAMap start...');
17987
18093
  return _context9.abrupt("return", new Promise(function (resolve, reject) {
17988
18094
  var _window4;
17989
- if (!((_window4 = window) !== null && _window4 !== void 0 && _window4.TMap)) {
18095
+ if (!((_window4 = window) !== null && _window4 !== void 0 && _window4.AMap)) {
18096
+ console.error('getAddressDetailByAMap fail: AMap is undefinded');
18097
+ resolve(null);
18098
+ return;
18099
+ }
18100
+ if (position) {
18101
+ new window.AMap.Geocoder({
18102
+ radius: 500,
18103
+ extensions: 'all'
18104
+ }).getAddress([position.longitude, position.latitude], function (status, result) {
18105
+ // console.log(status)
18106
+ // console.log(result)
18107
+ if (status === 'complete' && result.info === 'OK' && result !== null && result !== void 0 && result.regeocode) {
18108
+ console.log("getAddressByAMap success:", result.regeocode);
18109
+ var addressComponent = result.regeocode.addressComponent || {};
18110
+ // 确保 country 字段被正确获取
18111
+ // 直接从高德地图 API 返回的数据中获取 country 字段
18112
+ var country = addressComponent.country || '';
18113
+ var aois = result.regeocode.aois || [];
18114
+ var pois = result.regeocode.pois || [];
18115
+ if (Array.isArray(addressComponent.city)) {
18116
+ addressComponent.city = addressComponent.city.join(',');
18117
+ }
18118
+ var street = addressComponent.street || (addressComponent.streetNumber && isObject$4(addressComponent.streetNumber) ? addressComponent.streetNumber.street : '');
18119
+ var number = addressComponent.streetNumber && isObject$4(addressComponent.streetNumber) ? addressComponent.streetNumber.number : addressComponent.streetNumber || '';
18120
+ if (Array.isArray(street)) {
18121
+ street = street.join(',');
18122
+ }
18123
+ if (Array.isArray(number)) {
18124
+ number = number.join(',');
18125
+ }
18126
+ var poiname = aois && aois[0] && aois[0].name || '';
18127
+ var detailAddr = street + number + poiname || '';
18128
+ var address = (addressComponent.province || '') + (addressComponent.city || '') + (addressComponent.district || '') + (detailAddr || '');
18129
+ var tmpFullDistrinct = (addressComponent.province || '') + (addressComponent.city || '') + (addressComponent.district || '');
18130
+ if (!address.endsWith(poiname)) {
18131
+ address = address + poiname;
18132
+ }
18133
+ var selectedDetailAddr = detailAddr || '';
18134
+ // 去除前面的行政区域
18135
+ if (selectedDetailAddr.startsWith(tmpFullDistrinct)) {
18136
+ selectedDetailAddr = selectedDetailAddr.slice(tmpFullDistrinct.length);
18137
+ }
18138
+ pois && pois[0] && pois[0].id;
18139
+ pois && pois[0] && pois[0].type;
18140
+ var addressDetail = {
18141
+ regeocode: result.regeocode,
18142
+ addressDetail: {
18143
+ longitude: position.longitude,
18144
+ latitude: position.latitude,
18145
+ address: address || '',
18146
+ // poiname: poiname || '',
18147
+ regionid: addressComponent.adcode || '',
18148
+ country: country || '',
18149
+ province: addressComponent.province || '',
18150
+ city: addressComponent.city || '',
18151
+ district: addressComponent.district || addressComponent.township || '',
18152
+ street: street || '',
18153
+ number: number || '',
18154
+ detailaddr: selectedDetailAddr || ''
18155
+ // poiid: poiid || '',
18156
+ // poitypename: poitypename || '',
18157
+ // poitypecode: '',
18158
+ // phonenumber: getPoiPhoneNumber(pois && pois[0] && pois[0].tel),
18159
+ // signboard: '',
18160
+ // maptype: 'amap',
18161
+ }
18162
+ };
18163
+
18164
+ resolve(addressDetail);
18165
+ } else {
18166
+ console.error("getAddressByAMap fail: status = ".concat(status, ", result = ").concat(result));
18167
+ resolve(null);
18168
+ }
18169
+ });
18170
+ }
18171
+ }));
18172
+ case 2:
18173
+ case "end":
18174
+ return _context9.stop();
18175
+ }
18176
+ }, _callee9);
18177
+ }));
18178
+ return function getAddressDetailByAMap(_x6) {
18179
+ return _ref9.apply(this, arguments);
18180
+ };
18181
+ }();
18182
+ // 腾讯ip定位:通过终端设备IP地址获取其当前所在地理位置,精确到市级,常用于显示当地城市天气预报、初始化用户城市等非精确定位场景。
18183
+ var getIPLocationByTMap = /*#__PURE__*/function () {
18184
+ var _ref10 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee10(ip) {
18185
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
18186
+ while (1) switch (_context10.prev = _context10.next) {
18187
+ case 0:
18188
+ console.log('getIPLocationByTMap start...');
18189
+ return _context10.abrupt("return", new Promise(function (resolve, reject) {
18190
+ var _window5;
18191
+ if (!((_window5 = window) !== null && _window5 !== void 0 && _window5.TMap)) {
17990
18192
  console.error('getIPLocationByTMap fail: TMap is undefinded');
17991
18193
  resolve(null);
17992
18194
  return;
@@ -18011,24 +18213,24 @@ var getIPLocationByTMap = /*#__PURE__*/function () {
18011
18213
  }));
18012
18214
  case 2:
18013
18215
  case "end":
18014
- return _context9.stop();
18216
+ return _context10.stop();
18015
18217
  }
18016
- }, _callee9);
18218
+ }, _callee10);
18017
18219
  }));
18018
- return function getIPLocationByTMap(_x6) {
18019
- return _ref9.apply(this, arguments);
18220
+ return function getIPLocationByTMap(_x7) {
18221
+ return _ref10.apply(this, arguments);
18020
18222
  };
18021
18223
  }();
18022
18224
  // 腾讯逆地址解析
18023
18225
  var getAddressByTMap = /*#__PURE__*/function () {
18024
- var _ref10 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee10(position) {
18025
- return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
18026
- while (1) switch (_context10.prev = _context10.next) {
18226
+ var _ref11 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee11(position) {
18227
+ return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
18228
+ while (1) switch (_context11.prev = _context11.next) {
18027
18229
  case 0:
18028
18230
  console.log('getAddressByTMap start...');
18029
- return _context10.abrupt("return", new Promise(function (resolve, reject) {
18030
- var _window5;
18031
- if (!((_window5 = window) !== null && _window5 !== void 0 && _window5.TMap)) {
18231
+ return _context11.abrupt("return", new Promise(function (resolve, reject) {
18232
+ var _window6;
18233
+ if (!((_window6 = window) !== null && _window6 !== void 0 && _window6.TMap)) {
18032
18234
  console.error('getAddressByTMap fail: TMap is undefinded');
18033
18235
  resolve('');
18034
18236
  return;
@@ -18055,41 +18257,41 @@ var getAddressByTMap = /*#__PURE__*/function () {
18055
18257
  }));
18056
18258
  case 2:
18057
18259
  case "end":
18058
- return _context10.stop();
18260
+ return _context11.stop();
18059
18261
  }
18060
- }, _callee10);
18262
+ }, _callee11);
18061
18263
  }));
18062
- return function getAddressByTMap(_x7) {
18063
- return _ref10.apply(this, arguments);
18264
+ return function getAddressByTMap(_x8) {
18265
+ return _ref11.apply(this, arguments);
18064
18266
  };
18065
18267
  }();
18066
18268
  // 百度浏览器定位
18067
18269
  var getLocationByBMap = /*#__PURE__*/function () {
18068
- var _ref11 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee12() {
18069
- return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
18070
- while (1) switch (_context12.prev = _context12.next) {
18270
+ var _ref12 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee13() {
18271
+ return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
18272
+ while (1) switch (_context13.prev = _context13.next) {
18071
18273
  case 0:
18072
18274
  console.log('getLocationByBMap start...');
18073
- return _context12.abrupt("return", new Promise(function (resolve, reject) {
18074
- var _window6;
18075
- if (!((_window6 = window) !== null && _window6 !== void 0 && _window6.BMap)) {
18275
+ return _context13.abrupt("return", new Promise(function (resolve, reject) {
18276
+ var _window7;
18277
+ if (!((_window7 = window) !== null && _window7 !== void 0 && _window7.BMap)) {
18076
18278
  console.error('getLocationByBMap fail: BMap is undefinded');
18077
18279
  resolve(null);
18078
18280
  return;
18079
18281
  }
18080
18282
  new window.BMap.Geolocation().getCurrentPosition( /*#__PURE__*/function () {
18081
- var _ref12 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee11(res) {
18283
+ var _ref13 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee12(res) {
18082
18284
  var lng, lat, result;
18083
- return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
18084
- while (1) switch (_context11.prev = _context11.next) {
18285
+ return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
18286
+ while (1) switch (_context12.prev = _context12.next) {
18085
18287
  case 0:
18086
18288
  if (res) {
18087
- _context11.next = 4;
18289
+ _context12.next = 4;
18088
18290
  break;
18089
18291
  }
18090
18292
  console.error('getLocationByBMap fail');
18091
18293
  resolve(null);
18092
- return _context11.abrupt("return");
18294
+ return _context12.abrupt("return");
18093
18295
  case 4:
18094
18296
  // 初始化已经指定 window.BMap.coordType = 'BMAP_COORD_GCJ02' 定位返回的定位信息,外层[latitude,longitude]依然是BD09,然后point里面的是GCJ02
18095
18297
  // {
@@ -18132,12 +18334,12 @@ var getLocationByBMap = /*#__PURE__*/function () {
18132
18334
  resolve(result);
18133
18335
  case 9:
18134
18336
  case "end":
18135
- return _context11.stop();
18337
+ return _context12.stop();
18136
18338
  }
18137
- }, _callee11);
18339
+ }, _callee12);
18138
18340
  }));
18139
- return function (_x8) {
18140
- return _ref12.apply(this, arguments);
18341
+ return function (_x9) {
18342
+ return _ref13.apply(this, arguments);
18141
18343
  };
18142
18344
  }(), {
18143
18345
  enableHighAccuracy: true
@@ -18145,49 +18347,49 @@ var getLocationByBMap = /*#__PURE__*/function () {
18145
18347
  }));
18146
18348
  case 2:
18147
18349
  case "end":
18148
- return _context12.stop();
18350
+ return _context13.stop();
18149
18351
  }
18150
- }, _callee12);
18352
+ }, _callee13);
18151
18353
  }));
18152
18354
  return function getLocationByBMap() {
18153
- return _ref11.apply(this, arguments);
18355
+ return _ref12.apply(this, arguments);
18154
18356
  };
18155
18357
  }();
18156
18358
  // 百度城市定位
18157
18359
  var getCityLocationByBMap = /*#__PURE__*/function () {
18158
- var _ref13 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee14() {
18159
- return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
18160
- while (1) switch (_context14.prev = _context14.next) {
18360
+ var _ref14 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee15() {
18361
+ return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
18362
+ while (1) switch (_context15.prev = _context15.next) {
18161
18363
  case 0:
18162
18364
  console.log('getCityLocationByBMap start...');
18163
- return _context14.abrupt("return", new Promise(function (resolve, reject) {
18164
- var _window7;
18165
- if (!((_window7 = window) !== null && _window7 !== void 0 && _window7.BMap)) {
18365
+ return _context15.abrupt("return", new Promise(function (resolve, reject) {
18366
+ var _window8;
18367
+ if (!((_window8 = window) !== null && _window8 !== void 0 && _window8.BMap)) {
18166
18368
  console.error('getCityLocationByBMap fail: BMap is undefinded');
18167
18369
  resolve(null);
18168
18370
  return;
18169
18371
  }
18170
18372
  new window.BMap.LocalCity().get( /*#__PURE__*/function () {
18171
- var _ref14 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee13(res) {
18373
+ var _ref15 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee14(res) {
18172
18374
  var lng, lat, point, result;
18173
- return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
18174
- while (1) switch (_context13.prev = _context13.next) {
18375
+ return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
18376
+ while (1) switch (_context14.prev = _context14.next) {
18175
18377
  case 0:
18176
18378
  // console.log(res)
18177
18379
  // debugger
18178
18380
  lng = res.center.lng.toString();
18179
18381
  lat = res.center.lat.toString();
18180
18382
  if (!(lng && lat)) {
18181
- _context13.next = 11;
18383
+ _context14.next = 11;
18182
18384
  break;
18183
18385
  }
18184
- _context13.next = 5;
18386
+ _context14.next = 5;
18185
18387
  return BMapTransformBD09ToGCJ02Points([{
18186
18388
  lng: lng,
18187
18389
  lat: lat
18188
18390
  }]);
18189
18391
  case 5:
18190
- point = _context13.sent;
18392
+ point = _context14.sent;
18191
18393
  // console.log(point)
18192
18394
  // debugger
18193
18395
  result = {
@@ -18196,61 +18398,61 @@ var getCityLocationByBMap = /*#__PURE__*/function () {
18196
18398
  };
18197
18399
  console.log("getCityLocationByBMap success: ".concat(JSON.stringify(result)));
18198
18400
  resolve(result);
18199
- _context13.next = 13;
18401
+ _context14.next = 13;
18200
18402
  break;
18201
18403
  case 11:
18202
18404
  console.error('getCityLocationByBMap fail');
18203
18405
  resolve(null);
18204
18406
  case 13:
18205
18407
  case "end":
18206
- return _context13.stop();
18408
+ return _context14.stop();
18207
18409
  }
18208
- }, _callee13);
18410
+ }, _callee14);
18209
18411
  }));
18210
- return function (_x9) {
18211
- return _ref14.apply(this, arguments);
18412
+ return function (_x10) {
18413
+ return _ref15.apply(this, arguments);
18212
18414
  };
18213
18415
  }());
18214
18416
  }));
18215
18417
  case 2:
18216
18418
  case "end":
18217
- return _context14.stop();
18419
+ return _context15.stop();
18218
18420
  }
18219
- }, _callee14);
18421
+ }, _callee15);
18220
18422
  }));
18221
18423
  return function getCityLocationByBMap() {
18222
- return _ref13.apply(this, arguments);
18424
+ return _ref14.apply(this, arguments);
18223
18425
  };
18224
18426
  }();
18225
18427
  // 百度逆地址解析
18226
18428
  var getAddressByBmap = /*#__PURE__*/function () {
18227
- var _ref15 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee16(position) {
18228
- return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
18229
- while (1) switch (_context16.prev = _context16.next) {
18429
+ var _ref16 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee17(position) {
18430
+ return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
18431
+ while (1) switch (_context17.prev = _context17.next) {
18230
18432
  case 0:
18231
18433
  console.log('getAddressByBmap start...');
18232
- return _context16.abrupt("return", new Promise( /*#__PURE__*/function () {
18233
- var _ref16 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee15(resolve, reject) {
18234
- var _window8;
18434
+ return _context17.abrupt("return", new Promise( /*#__PURE__*/function () {
18435
+ var _ref17 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee16(resolve, reject) {
18436
+ var _window9;
18235
18437
  var point;
18236
- return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
18237
- while (1) switch (_context15.prev = _context15.next) {
18438
+ return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
18439
+ while (1) switch (_context16.prev = _context16.next) {
18238
18440
  case 0:
18239
- if ((_window8 = window) !== null && _window8 !== void 0 && _window8.BMap) {
18240
- _context15.next = 4;
18441
+ if ((_window9 = window) !== null && _window9 !== void 0 && _window9.BMap) {
18442
+ _context16.next = 4;
18241
18443
  break;
18242
18444
  }
18243
18445
  console.error('getAddressByBmap fail: BMap is undefinded');
18244
18446
  resolve('');
18245
- return _context15.abrupt("return");
18447
+ return _context16.abrupt("return");
18246
18448
  case 4:
18247
18449
  if (position) {
18248
- _context15.next = 8;
18450
+ _context16.next = 8;
18249
18451
  break;
18250
18452
  }
18251
18453
  console.error('getAddressByBmap fail');
18252
18454
  resolve('');
18253
- return _context15.abrupt("return");
18455
+ return _context16.abrupt("return");
18254
18456
  case 8:
18255
18457
  // // 把 GCJ02 转化为百度 BD09 地址
18256
18458
  // const points: any = await transformGCJ02ToBD09Points([{
@@ -18275,104 +18477,104 @@ var getAddressByBmap = /*#__PURE__*/function () {
18275
18477
  });
18276
18478
  case 10:
18277
18479
  case "end":
18278
- return _context15.stop();
18480
+ return _context16.stop();
18279
18481
  }
18280
- }, _callee15);
18482
+ }, _callee16);
18281
18483
  }));
18282
- return function (_x11, _x12) {
18283
- return _ref16.apply(this, arguments);
18484
+ return function (_x12, _x13) {
18485
+ return _ref17.apply(this, arguments);
18284
18486
  };
18285
18487
  }()));
18286
18488
  case 2:
18287
18489
  case "end":
18288
- return _context16.stop();
18490
+ return _context17.stop();
18289
18491
  }
18290
- }, _callee16);
18492
+ }, _callee17);
18291
18493
  }));
18292
- return function getAddressByBmap(_x10) {
18293
- return _ref15.apply(this, arguments);
18494
+ return function getAddressByBmap(_x11) {
18495
+ return _ref16.apply(this, arguments);
18294
18496
  };
18295
18497
  }();
18296
18498
  var getLocationPromise = /*#__PURE__*/function () {
18297
- var _ref17 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee17() {
18298
- var _window9;
18499
+ var _ref18 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee18() {
18500
+ var _window10;
18299
18501
  var isuseiplocation,
18300
18502
  location,
18301
- _args17 = arguments;
18302
- return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
18303
- while (1) switch (_context17.prev = _context17.next) {
18503
+ _args18 = arguments;
18504
+ return _regeneratorRuntime$1().wrap(function _callee18$(_context18) {
18505
+ while (1) switch (_context18.prev = _context18.next) {
18304
18506
  case 0:
18305
- isuseiplocation = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : false;
18507
+ isuseiplocation = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : false;
18306
18508
  location = null; // 在 SPU 容器里使用 Native-API 的定位
18307
- if (!((_window9 = window) !== null && _window9 !== void 0 && (_window9 = _window9.Native) !== null && _window9 !== void 0 && _window9.getLocation)) {
18308
- _context17.next = 6;
18509
+ if (!((_window10 = window) !== null && _window10 !== void 0 && (_window10 = _window10.Native) !== null && _window10 !== void 0 && _window10.getLocation)) {
18510
+ _context18.next = 6;
18309
18511
  break;
18310
18512
  }
18311
- _context17.next = 5;
18513
+ _context18.next = 5;
18312
18514
  return getLocationByNative();
18313
18515
  case 5:
18314
- location = _context17.sent;
18516
+ location = _context18.sent;
18315
18517
  case 6:
18316
18518
  if (location) {
18317
- _context17.next = 31;
18519
+ _context18.next = 31;
18318
18520
  break;
18319
18521
  }
18320
18522
  if (!(mapService.type === 'amap')) {
18321
- _context17.next = 17;
18523
+ _context18.next = 17;
18322
18524
  break;
18323
18525
  }
18324
- _context17.next = 10;
18526
+ _context18.next = 10;
18325
18527
  return getLocationByAMap();
18326
18528
  case 10:
18327
- location = _context17.sent;
18529
+ location = _context18.sent;
18328
18530
  if (!(!location && isuseiplocation)) {
18329
- _context17.next = 15;
18531
+ _context18.next = 15;
18330
18532
  break;
18331
18533
  }
18332
- _context17.next = 14;
18534
+ _context18.next = 14;
18333
18535
  return getCityLocationByAMap();
18334
18536
  case 14:
18335
- location = _context17.sent;
18537
+ location = _context18.sent;
18336
18538
  case 15:
18337
- _context17.next = 31;
18539
+ _context18.next = 31;
18338
18540
  break;
18339
18541
  case 17:
18340
18542
  if (!(mapService.type === 'tencent' && isuseiplocation)) {
18341
- _context17.next = 23;
18543
+ _context18.next = 23;
18342
18544
  break;
18343
18545
  }
18344
- _context17.next = 20;
18546
+ _context18.next = 20;
18345
18547
  return getIPLocationByTMap();
18346
18548
  case 20:
18347
- location = _context17.sent;
18348
- _context17.next = 31;
18549
+ location = _context18.sent;
18550
+ _context18.next = 31;
18349
18551
  break;
18350
18552
  case 23:
18351
18553
  if (!(mapService.type === 'baidu')) {
18352
- _context17.next = 31;
18554
+ _context18.next = 31;
18353
18555
  break;
18354
18556
  }
18355
- _context17.next = 26;
18557
+ _context18.next = 26;
18356
18558
  return getLocationByBMap();
18357
18559
  case 26:
18358
- location = _context17.sent;
18560
+ location = _context18.sent;
18359
18561
  if (!(!location && isuseiplocation)) {
18360
- _context17.next = 31;
18562
+ _context18.next = 31;
18361
18563
  break;
18362
18564
  }
18363
- _context17.next = 30;
18565
+ _context18.next = 30;
18364
18566
  return getCityLocationByBMap();
18365
18567
  case 30:
18366
- location = _context17.sent;
18568
+ location = _context18.sent;
18367
18569
  case 31:
18368
18570
  if (location) {
18369
- _context17.next = 35;
18571
+ _context18.next = 35;
18370
18572
  break;
18371
18573
  }
18372
- _context17.next = 34;
18574
+ _context18.next = 34;
18373
18575
  return getLocationByNavigator();
18374
18576
  case 34:
18375
- location = _context17.sent;
18577
+ location = _context18.sent;
18376
18578
  case 35:
18377
18579
  // location = null
18378
18580
  // 开发模式下为了方便测试提供虚拟定位
@@ -18396,30 +18598,30 @@ var getLocationPromise = /*#__PURE__*/function () {
18396
18598
  // }
18397
18599
  // }
18398
18600
  if (!(location && !location.address)) {
18399
- _context17.next = 43;
18601
+ _context18.next = 43;
18400
18602
  break;
18401
18603
  }
18402
- _context17.next = 39;
18604
+ _context18.next = 39;
18403
18605
  return getAddress(location);
18404
18606
  case 39:
18405
- _context17.t0 = _context17.sent;
18406
- if (_context17.t0) {
18407
- _context17.next = 42;
18607
+ _context18.t0 = _context18.sent;
18608
+ if (_context18.t0) {
18609
+ _context18.next = 42;
18408
18610
  break;
18409
18611
  }
18410
- _context17.t0 = '经纬度获取成功,但地址获取失败。';
18612
+ _context18.t0 = '经纬度获取成功,但地址获取失败。';
18411
18613
  case 42:
18412
- location.address = _context17.t0;
18614
+ location.address = _context18.t0;
18413
18615
  case 43:
18414
- return _context17.abrupt("return", location);
18616
+ return _context18.abrupt("return", location);
18415
18617
  case 44:
18416
18618
  case "end":
18417
- return _context17.stop();
18619
+ return _context18.stop();
18418
18620
  }
18419
- }, _callee17);
18621
+ }, _callee18);
18420
18622
  }));
18421
18623
  return function getLocationPromise() {
18422
- return _ref17.apply(this, arguments);
18624
+ return _ref18.apply(this, arguments);
18423
18625
  };
18424
18626
  }();
18425
18627
  // WGS84 GCJ-02 BD-09 坐标系
@@ -18429,104 +18631,104 @@ function getLocation() {
18429
18631
  return _getLocation.apply(this, arguments);
18430
18632
  } // 逆地址解析
18431
18633
  function _getLocation() {
18432
- _getLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee20() {
18634
+ _getLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee21() {
18433
18635
  var isuseiplocation,
18434
18636
  locationRes,
18435
- _args20 = arguments;
18436
- return _regeneratorRuntime$1().wrap(function _callee20$(_context20) {
18437
- while (1) switch (_context20.prev = _context20.next) {
18637
+ _args21 = arguments;
18638
+ return _regeneratorRuntime$1().wrap(function _callee21$(_context21) {
18639
+ while (1) switch (_context21.prev = _context21.next) {
18438
18640
  case 0:
18439
- isuseiplocation = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : false;
18440
- _context20.next = 3;
18641
+ isuseiplocation = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : false;
18642
+ _context21.next = 3;
18441
18643
  return mapService.init();
18442
18644
  case 3:
18443
18645
  if (!(datetime && Date.now() - datetime <= cachetime && lastLocation && !runing)) {
18444
- _context20.next = 5;
18646
+ _context21.next = 5;
18445
18647
  break;
18446
18648
  }
18447
- return _context20.abrupt("return", cloneDeep$1(lastLocation));
18649
+ return _context21.abrupt("return", cloneDeep$1(lastLocation));
18448
18650
  case 5:
18449
18651
  if (!(runing && locationPromise)) {
18450
- _context20.next = 7;
18652
+ _context21.next = 7;
18451
18653
  break;
18452
18654
  }
18453
- return _context20.abrupt("return", locationPromise);
18655
+ return _context21.abrupt("return", locationPromise);
18454
18656
  case 7:
18455
18657
  // console.log('runing')
18456
18658
  runing = true;
18457
18659
  locationPromise = getLocationPromise(isuseiplocation);
18458
- _context20.next = 11;
18660
+ _context21.next = 11;
18459
18661
  return locationPromise;
18460
18662
  case 11:
18461
- locationRes = _context20.sent;
18663
+ locationRes = _context21.sent;
18462
18664
  runing = false;
18463
18665
  if (locationRes) {
18464
18666
  datetime = Date.now();
18465
18667
  lastLocation = locationRes;
18466
18668
  }
18467
- return _context20.abrupt("return", locationRes);
18669
+ return _context21.abrupt("return", locationRes);
18468
18670
  case 15:
18469
18671
  case "end":
18470
- return _context20.stop();
18672
+ return _context21.stop();
18471
18673
  }
18472
- }, _callee20);
18674
+ }, _callee21);
18473
18675
  }));
18474
18676
  return _getLocation.apply(this, arguments);
18475
18677
  }
18476
18678
  var getAddress = /*#__PURE__*/function () {
18477
- var _ref18 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee18(position) {
18679
+ var _ref19 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee19(position) {
18478
18680
  var address;
18479
- return _regeneratorRuntime$1().wrap(function _callee18$(_context18) {
18480
- while (1) switch (_context18.prev = _context18.next) {
18681
+ return _regeneratorRuntime$1().wrap(function _callee19$(_context19) {
18682
+ while (1) switch (_context19.prev = _context19.next) {
18481
18683
  case 0:
18482
- _context18.next = 2;
18684
+ _context19.next = 2;
18483
18685
  return mapService.init();
18484
18686
  case 2:
18485
18687
  address = '';
18486
18688
  if (address) {
18487
- _context18.next = 20;
18689
+ _context19.next = 20;
18488
18690
  break;
18489
18691
  }
18490
18692
  if (!(mapService.type === 'amap')) {
18491
- _context18.next = 10;
18693
+ _context19.next = 10;
18492
18694
  break;
18493
18695
  }
18494
- _context18.next = 7;
18696
+ _context19.next = 7;
18495
18697
  return getAddressByAMap(position);
18496
18698
  case 7:
18497
- address = _context18.sent;
18498
- _context18.next = 20;
18699
+ address = _context19.sent;
18700
+ _context19.next = 20;
18499
18701
  break;
18500
18702
  case 10:
18501
18703
  if (!(mapService.type === 'tencent')) {
18502
- _context18.next = 16;
18704
+ _context19.next = 16;
18503
18705
  break;
18504
18706
  }
18505
- _context18.next = 13;
18707
+ _context19.next = 13;
18506
18708
  return getAddressByTMap(position);
18507
18709
  case 13:
18508
- address = _context18.sent;
18509
- _context18.next = 20;
18710
+ address = _context19.sent;
18711
+ _context19.next = 20;
18510
18712
  break;
18511
18713
  case 16:
18512
18714
  if (!(mapService.type === 'baidu')) {
18513
- _context18.next = 20;
18715
+ _context19.next = 20;
18514
18716
  break;
18515
18717
  }
18516
- _context18.next = 19;
18718
+ _context19.next = 19;
18517
18719
  return getAddressByBmap(position);
18518
18720
  case 19:
18519
- address = _context18.sent;
18721
+ address = _context19.sent;
18520
18722
  case 20:
18521
- return _context18.abrupt("return", address);
18723
+ return _context19.abrupt("return", address);
18522
18724
  case 21:
18523
18725
  case "end":
18524
- return _context18.stop();
18726
+ return _context19.stop();
18525
18727
  }
18526
- }, _callee18);
18728
+ }, _callee19);
18527
18729
  }));
18528
- return function getAddress(_x13) {
18529
- return _ref18.apply(this, arguments);
18730
+ return function getAddress(_x14) {
18731
+ return _ref19.apply(this, arguments);
18530
18732
  };
18531
18733
  }();
18532
18734
  // const getDistance = async (p1: [number, number], p2: [number, number]) => {
@@ -18535,10 +18737,10 @@ var getAddress = /*#__PURE__*/function () {
18535
18737
  // }
18536
18738
  // 两个经纬度距离计算
18537
18739
  var getDistance = /*#__PURE__*/function () {
18538
- var _ref19 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee19(latlng1, latlng2) {
18740
+ var _ref20 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee20(latlng1, latlng2) {
18539
18741
  var lng1, lat1, lng2, lat2, radLat1, radLat2, a, b, s;
18540
- return _regeneratorRuntime$1().wrap(function _callee19$(_context19) {
18541
- while (1) switch (_context19.prev = _context19.next) {
18742
+ return _regeneratorRuntime$1().wrap(function _callee20$(_context20) {
18743
+ while (1) switch (_context20.prev = _context20.next) {
18542
18744
  case 0:
18543
18745
  // console.log(latlng1)
18544
18746
  // console.log(latlng2)
@@ -18553,15 +18755,15 @@ var getDistance = /*#__PURE__*/function () {
18553
18755
  s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
18554
18756
  s = s * 6378.137; // EARTH_RADIUS
18555
18757
  s = Math.round(s * 10000) / 10000;
18556
- return _context19.abrupt("return", s * 1000);
18758
+ return _context20.abrupt("return", s * 1000);
18557
18759
  case 12:
18558
18760
  case "end":
18559
- return _context19.stop();
18761
+ return _context20.stop();
18560
18762
  }
18561
- }, _callee19);
18763
+ }, _callee20);
18562
18764
  }));
18563
- return function getDistance(_x14, _x15) {
18564
- return _ref19.apply(this, arguments);
18765
+ return function getDistance(_x15, _x16) {
18766
+ return _ref20.apply(this, arguments);
18565
18767
  };
18566
18768
  }();
18567
18769
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "1.0.24",
3
+ "version": "1.0.25-beta.2",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "npm run build:types && rollup -c -w",
@@ -29,6 +29,7 @@
29
29
  "@rollup/plugin-node-resolve": "^15.2.3",
30
30
  "@rollup/plugin-terser": "^0.4.4",
31
31
  "@rollup/plugin-typescript": "^11.1.5",
32
+ "@rollup/rollup-darwin-x64": "^4.53.3",
32
33
  "@types/crypto-js": "^4.2.2",
33
34
  "@types/lodash-es": "^4.17.10",
34
35
  "@types/node": "^20.8.10",
@@ -52,4 +53,4 @@
52
53
  "uuid": "^9.0.1",
53
54
  "vconsole": "^3.15.1"
54
55
  }
55
- }
56
+ }
package/src/map/index.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { urlquery } from '../urlquery'
2
- import { cloneDeep } from 'lodash-es'
2
+ import { cloneDeep, isObject } from 'lodash-es'
3
3
  import { mapService } from './MapService'
4
4
  import { getAMapKey } from './AMapKey'
5
5
  import { axios } from '../axios'
6
6
  import { delay } from '../utils'
7
- import { wgs84ToGcj02, BMapTransformBD09ToGCJ02Points } from './utils'
7
+ import { wgs84ToGcj02, BMapTransformBD09ToGCJ02Points, getPoiPhoneNumber } from './utils'
8
8
 
9
9
  type Location = {
10
10
  longitude: string
@@ -39,7 +39,22 @@ const getLocationByNative = async (): Promise<Location> => {
39
39
  const result = {
40
40
  longitude: res.longitude.toString(),
41
41
  latitude: res.latitude.toString(),
42
- address: res.address || ''
42
+ address: res.address || '',
43
+ // poiname: res.poiname || '',
44
+ regionid: res.regionid || '',
45
+ country: res.country || '',
46
+ province: res.province || '',
47
+ city: res.city || '',
48
+ district: res.district || '',
49
+ street: res.street || '',
50
+ number: res.number || '',
51
+ detailaddr: res.detailaddr || '',
52
+ // poiid: res.poiid || '',
53
+ // poitypename: res.poitypename || '',
54
+ // poitypecode: res.poitypecode || '',
55
+ // phonenumber: res.phonenumber || '',
56
+ // signboard: res.signboard || '',
57
+ // maptype: res.maptype || '',
43
58
  }
44
59
  console.log(`getLocationByNative success: ${JSON.stringify(result)}`)
45
60
  resolve(result)
@@ -74,6 +89,7 @@ const getLocationByNavigator = async (): Promise<Location> => {
74
89
  latitude: Gcj02.lat.toString(),
75
90
  longitude: Gcj02.lng.toString()
76
91
  }
92
+
77
93
  console.log(`getLocationByNavigator success: ${JSON.stringify(result)}`)
78
94
  resolve(result)
79
95
  } else {
@@ -196,10 +212,54 @@ const getLocationByAMap = async (): Promise<Location> => {
196
212
  const { lng, lat } = res.position
197
213
  const result = {
198
214
  longitude: lng.toString(),
199
- latitude: lat.toString()
215
+ latitude: lat.toString(),
216
+ address: '',
217
+ // poiname: '',
218
+ regionid: '',
219
+ country: '',
220
+ province: '',
221
+ city: '',
222
+ district: '',
223
+ street: '',
224
+ number: '',
225
+ detailaddr: '',
226
+ // poiid: '', // 图商的id
227
+ // poitypename: '', // 图商的poi类型名称
228
+ // poitypecode: '', // 图商的poi类型code
229
+ // phonenumber: '',
230
+ // signboard: '',
231
+ // maptype: "amap"
200
232
  }
201
- console.log(`getLocationByAMap success: ${JSON.stringify(result)}`)
202
- resolve(result)
233
+ // 通过经纬度获取详细地址信息
234
+ getAddressDetailByAMap({
235
+ longitude: lng.toString(),
236
+ latitude: lat.toString()
237
+ }).then((addrssDetail: IAddressDetail | null) => {
238
+ if (addrssDetail) {
239
+ result.address = addrssDetail.addressDetail.address
240
+ // result.poiname = addrssDetail.addressDetail.poiname
241
+ result.regionid = addrssDetail.addressDetail.regionid
242
+ result.country = addrssDetail.addressDetail.country
243
+ result.province = addrssDetail.addressDetail.province
244
+ result.city = addrssDetail.addressDetail.city
245
+ result.district = addrssDetail.addressDetail.district
246
+ result.street = addrssDetail.addressDetail.street
247
+ result.number = addrssDetail.addressDetail.number
248
+ result.detailaddr = addrssDetail.addressDetail.detailaddr
249
+ // result.poiid = addrssDetail.addressDetail.poiid
250
+ // result.poitypename = addrssDetail.addressDetail.poitypename
251
+ // result.poitypecode = addrssDetail.addressDetail.poitypecode
252
+ // result.phonenumber = addrssDetail.addressDetail.phonenumber
253
+ // result.signboard = addrssDetail.addressDetail.signboard
254
+ }
255
+ console.log(`getLocationByAMap success: ${JSON.stringify(result)}`)
256
+ resolve(result)
257
+ }).catch((err: any) => {
258
+ console.error(err)
259
+ console.error('getLocationByAMap fail')
260
+ resolve(null)
261
+ })
262
+
203
263
  } else {
204
264
  console.error('getLocationByAMap fail')
205
265
  resolve(null)
@@ -228,10 +288,55 @@ const getCityLocationByAMap = async (): Promise<Location> => {
228
288
  const lat = res.position[1].toString()
229
289
  const result = {
230
290
  longitude: lng.toString(),
231
- latitude: lat.toString()
291
+ latitude: lat.toString(),
292
+ address: '',
293
+ // poiname: '',
294
+ regionid: '',
295
+ country: '',
296
+ province: '',
297
+ city: '',
298
+ district: '',
299
+ street: '',
300
+ number: '',
301
+ detailaddr: '',
302
+ // poiid: '', // 图商的id
303
+ // poitypename: '', // 图商的poi类型名称
304
+ // poitypecode: '', // 图商的poi类型code
305
+ // phonenumber: '',
306
+ // signboard: '',
307
+ // maptype: "amap"
232
308
  }
233
309
  console.log(`getCityLocationByAMap success: ${JSON.stringify(result)}`)
234
- resolve(result)
310
+
311
+ // 通过经纬度获取详细地址信息
312
+ getAddressDetailByAMap({
313
+ longitude: lng.toString(),
314
+ latitude: lat.toString()
315
+ }).then((addrssDetail: IAddressDetail | null) => {
316
+ if (addrssDetail) {
317
+ result.address = addrssDetail.addressDetail.address
318
+ // result.poiname = addrssDetail.addressDetail.poiname
319
+ result.regionid = addrssDetail.addressDetail.regionid
320
+ result.country = addrssDetail.addressDetail.country
321
+ result.province = addrssDetail.addressDetail.province
322
+ result.city = addrssDetail.addressDetail.city
323
+ result.district = addrssDetail.addressDetail.district
324
+ result.street = addrssDetail.addressDetail.street
325
+ result.number = addrssDetail.addressDetail.number
326
+ result.detailaddr = addrssDetail.addressDetail.detailaddr
327
+ // result.poiid = addrssDetail.addressDetail.poiid
328
+ // result.poitypename = addrssDetail.addressDetail.poitypename
329
+ // result.poitypecode = addrssDetail.addressDetail.poitypecode
330
+ // result.phonenumber = addrssDetail.addressDetail.phonenumber
331
+ // result.signboard = addrssDetail.addressDetail.signboard
332
+ }
333
+ console.log(`getLocationByAMap success: ${JSON.stringify(result)}`)
334
+ resolve(result)
335
+ }).catch((err: any) => {
336
+ console.error(err)
337
+ console.error('getLocationByAMap fail')
338
+ resolve(null)
339
+ })
235
340
  } else {
236
341
  console.error('getCityLocationByAMap fail')
237
342
  resolve(null)
@@ -270,6 +375,127 @@ const getAddressByAMap = async (position: Location): Promise<string> => {
270
375
  })
271
376
  }
272
377
 
378
+ interface IAddressDetail {
379
+ regeocode: IAny
380
+ addressDetail: {
381
+ longitude: string
382
+ latitude: string
383
+ address: string
384
+ // poiname: string
385
+ regionid: string
386
+ country: string
387
+ province: string
388
+ city: string
389
+ district: string
390
+ street: string
391
+ number: string
392
+ detailaddr: string
393
+ // poiid: string
394
+ // poitypename: string
395
+ // poitypecode: string
396
+ // phonenumber: string
397
+ // signboard: string
398
+ // maptype: string
399
+ }
400
+ }
401
+ // 高德逆地址解析详细数据
402
+ const getAddressDetailByAMap = async (position: Location): Promise<IAddressDetail | null> => {
403
+ console.log('getAddressDetailByAMap start...')
404
+ return new Promise((resolve, reject) => {
405
+ if (!window?.AMap) {
406
+ console.error('getAddressDetailByAMap fail: AMap is undefinded')
407
+ resolve(null)
408
+ return
409
+ }
410
+ if (position) {
411
+ new window.AMap.Geocoder({
412
+ radius: 500,
413
+ extensions: 'all'
414
+ }).getAddress([position.longitude, position.latitude], (status: string, result: any) => {
415
+ // console.log(status)
416
+ // console.log(result)
417
+ if (status === 'complete' && result.info === 'OK' && result?.regeocode) {
418
+ console.log(`getAddressByAMap success:`, result.regeocode)
419
+
420
+ const addressComponent = result.regeocode.addressComponent || {}
421
+
422
+ // 确保 country 字段被正确获取
423
+ // 直接从高德地图 API 返回的数据中获取 country 字段
424
+ const country = addressComponent.country || ''
425
+
426
+ let aois = result.regeocode.aois || []
427
+ let pois = result.regeocode.pois || []
428
+ if (Array.isArray(addressComponent.city)) {
429
+ addressComponent.city = addressComponent.city.join(',')
430
+ }
431
+ let street = addressComponent.street || (addressComponent.streetNumber && isObject(addressComponent.streetNumber) ? addressComponent.streetNumber.street : '')
432
+ let number = addressComponent.streetNumber && isObject(addressComponent.streetNumber) ? addressComponent.streetNumber.number : (addressComponent.streetNumber || '')
433
+ if (Array.isArray(street)) {
434
+ street = street.join(',')
435
+ }
436
+ if (Array.isArray(number)) {
437
+ number = number.join(',')
438
+ }
439
+ let poiname = (aois && aois[0] && aois[0].name) || ''
440
+
441
+ let detailAddr =
442
+ street + number + poiname || ''
443
+
444
+ let address =
445
+ (addressComponent.province || '') +
446
+ (addressComponent.city || '') +
447
+ (addressComponent.district || '') +
448
+ (detailAddr || '')
449
+ let tmpFullDistrinct =
450
+ (addressComponent.province || '') +
451
+ (addressComponent.city || '') +
452
+ (addressComponent.district || '')
453
+ if (!address.endsWith(poiname)) {
454
+ address = address + poiname
455
+ }
456
+ let selectedDetailAddr = detailAddr || ''
457
+ // 去除前面的行政区域
458
+ if (selectedDetailAddr.startsWith(tmpFullDistrinct)) {
459
+ selectedDetailAddr = selectedDetailAddr.slice(tmpFullDistrinct.length)
460
+ }
461
+ let poiid = pois && pois[0] && pois[0].id
462
+ let poitypename = pois && pois[0] && pois[0].type
463
+
464
+ const addressDetail: IAddressDetail = {
465
+ regeocode: result.regeocode,
466
+ addressDetail: {
467
+ longitude: position.longitude,
468
+ latitude: position.latitude,
469
+ address: address || '',
470
+ // poiname: poiname || '',
471
+ regionid: addressComponent.adcode || '',
472
+ country: country || '',
473
+ province: addressComponent.province || '',
474
+ city: addressComponent.city || '',
475
+ district: addressComponent.district ||
476
+ addressComponent.township ||
477
+ '',
478
+ street: street || '',
479
+ number: number || '',
480
+ detailaddr: selectedDetailAddr || '',
481
+ // poiid: poiid || '',
482
+ // poitypename: poitypename || '',
483
+ // poitypecode: '',
484
+ // phonenumber: getPoiPhoneNumber(pois && pois[0] && pois[0].tel),
485
+ // signboard: '',
486
+ // maptype: 'amap',
487
+ }
488
+ }
489
+ resolve(addressDetail)
490
+ } else {
491
+ console.error(`getAddressByAMap fail: status = ${status}, result = ${result}`)
492
+ resolve(null)
493
+ }
494
+ })
495
+ }
496
+ })
497
+ }
498
+
273
499
  // 腾讯ip定位:通过终端设备IP地址获取其当前所在地理位置,精确到市级,常用于显示当地城市天气预报、初始化用户城市等非精确定位场景。
274
500
  const getIPLocationByTMap = async (ip?: string): Promise<Location> => {
275
501
  console.log('getIPLocationByTMap start...')
package/src/map/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- function transformLat (x: number, y: number) {
1
+ function transformLat(x: number, y: number) {
2
2
  let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x))
3
3
  ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0
4
4
  ret += (20.0 * Math.sin(y * Math.PI) + 40.0 * Math.sin(y / 3.0 * Math.PI)) * 2.0 / 3.0
@@ -6,7 +6,7 @@ function transformLat (x: number, y: number) {
6
6
  return ret
7
7
  }
8
8
 
9
- function transformLon (x: number, y: number) {
9
+ function transformLon(x: number, y: number) {
10
10
  let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x))
11
11
  ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0
12
12
  ret += (20.0 * Math.sin(x * Math.PI) + 40.0 * Math.sin(x / 3.0 * Math.PI)) * 2.0 / 3.0
@@ -14,11 +14,11 @@ function transformLon (x: number, y: number) {
14
14
  return ret
15
15
  }
16
16
 
17
- function outOfChina (lng: number, lat: number) {
17
+ function outOfChina(lng: number, lat: number) {
18
18
  return (lng < 72.004 || lng > 137.8347) || (lat < 0.8293 || lat > 55.8271)
19
19
  }
20
20
 
21
- function delta (lng: number, lat: number) {
21
+ function delta(lng: number, lat: number) {
22
22
  const a = 6378245.0 // 地球长半轴
23
23
  const ee = 0.00669342162296594323 // 扁率
24
24
  let dLat = transformLat(lng - 105.0, lat - 35.0)
@@ -35,7 +35,7 @@ function delta (lng: number, lat: number) {
35
35
  }
36
36
  }
37
37
 
38
- function wgs84ToGcj02 (lng: number, lat: number) {
38
+ function wgs84ToGcj02(lng: number, lat: number) {
39
39
  if (outOfChina(lng, lat)) {
40
40
  return {
41
41
  lng: lng,
@@ -96,3 +96,19 @@ export {
96
96
  BMapTransformBD09ToGCJ02Points,
97
97
  BMapTransformGCJ02ToBD09Points
98
98
  }
99
+
100
+
101
+ export const getPoiPhoneNumber = (tel: string | string[]) => {
102
+ if (Array.isArray(tel)) {
103
+ tel = tel.filter((item) => item).join(';')
104
+ }
105
+ // tel里面:020-84060333;13570071479 需要优先去除手机号,否则用电话
106
+ if (tel) {
107
+ const phoneReg = /1[3456789]\d{9}/
108
+ const phone = tel.match(phoneReg)
109
+ if (phone) {
110
+ return phone[0]
111
+ }
112
+ }
113
+ return tel
114
+ }