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

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.1";
2
2
 
3
3
  /** Detect free variable `global` from Node.js. */
4
4
  var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
@@ -17740,6 +17740,22 @@ var BMapTransformBD09ToGCJ02Points = function BMapTransformBD09ToGCJ02Points(poi
17740
17740
  });
17741
17741
  });
17742
17742
  };
17743
+ var getPoiPhoneNumber = function getPoiPhoneNumber(tel) {
17744
+ if (Array.isArray(tel)) {
17745
+ tel = tel.filter(function (item) {
17746
+ return item;
17747
+ }).join(';');
17748
+ }
17749
+ // tel里面:020-84060333;13570071479 需要优先去除手机号,否则用电话
17750
+ if (tel) {
17751
+ var phoneReg = /1[3456789]\d{9}/;
17752
+ var phone = tel.match(phoneReg);
17753
+ if (phone) {
17754
+ return phone[0];
17755
+ }
17756
+ }
17757
+ return tel;
17758
+ };
17743
17759
 
17744
17760
  var cachetime = 30000; // 缓存时间30秒
17745
17761
  var datetime = null;
@@ -17770,7 +17786,22 @@ var getLocationByNative = /*#__PURE__*/function () {
17770
17786
  var result = {
17771
17787
  longitude: res.longitude.toString(),
17772
17788
  latitude: res.latitude.toString(),
17773
- address: res.address || ''
17789
+ address: res.address || '',
17790
+ poiname: res.poiname || '',
17791
+ regionid: res.regionid || '',
17792
+ country: res.country || '',
17793
+ province: res.province || '',
17794
+ city: res.city || '',
17795
+ district: res.district || '',
17796
+ street: res.street || '',
17797
+ number: res.number || '',
17798
+ detailaddr: res.detailaddr || '',
17799
+ poiid: res.poiid || '',
17800
+ poitypename: res.poitypename || '',
17801
+ poitypecode: res.poitypecode || '',
17802
+ phonenumber: res.phonenumber || '',
17803
+ signboard: res.signboard || '',
17804
+ maptype: res.maptype || ''
17774
17805
  };
17775
17806
  console.log("getLocationByNative success: ".concat(JSON.stringify(result)));
17776
17807
  resolve(result);
@@ -17868,10 +17899,53 @@ var getLocationByAMap = /*#__PURE__*/function () {
17868
17899
  lat = _res$position.lat;
17869
17900
  var result = {
17870
17901
  longitude: lng.toString(),
17871
- latitude: lat.toString()
17902
+ latitude: lat.toString(),
17903
+ address: '',
17904
+ poiname: '',
17905
+ regionid: '',
17906
+ country: '',
17907
+ province: '',
17908
+ city: '',
17909
+ district: '',
17910
+ street: '',
17911
+ number: '',
17912
+ detailaddr: '',
17913
+ poiid: '',
17914
+ poitypename: '',
17915
+ poitypecode: '',
17916
+ phonenumber: '',
17917
+ signboard: '',
17918
+ maptype: "amap"
17872
17919
  };
17873
- console.log("getLocationByAMap success: ".concat(JSON.stringify(result)));
17874
- resolve(result);
17920
+ // 通过经纬度获取详细地址信息
17921
+ getAddressDetailByAMap({
17922
+ longitude: lng.toString(),
17923
+ latitude: lat.toString()
17924
+ }).then(function (addrssDetail) {
17925
+ if (addrssDetail) {
17926
+ result.address = addrssDetail.addressDetail.address;
17927
+ result.poiname = addrssDetail.addressDetail.poiname;
17928
+ result.regionid = addrssDetail.addressDetail.regionid;
17929
+ result.country = addrssDetail.addressDetail.country;
17930
+ result.province = addrssDetail.addressDetail.province;
17931
+ result.city = addrssDetail.addressDetail.city;
17932
+ result.district = addrssDetail.addressDetail.district;
17933
+ result.street = addrssDetail.addressDetail.street;
17934
+ result.number = addrssDetail.addressDetail.number;
17935
+ result.detailaddr = addrssDetail.addressDetail.detailaddr;
17936
+ result.poiid = addrssDetail.addressDetail.poiid;
17937
+ result.poitypename = addrssDetail.addressDetail.poitypename;
17938
+ result.poitypecode = addrssDetail.addressDetail.poitypecode;
17939
+ result.phonenumber = addrssDetail.addressDetail.phonenumber;
17940
+ result.signboard = addrssDetail.addressDetail.signboard;
17941
+ }
17942
+ console.log("getLocationByAMap success: ".concat(JSON.stringify(result)));
17943
+ resolve(result);
17944
+ })["catch"](function (err) {
17945
+ console.error(err);
17946
+ console.error('getLocationByAMap fail');
17947
+ resolve(null);
17948
+ });
17875
17949
  } else {
17876
17950
  console.error('getLocationByAMap fail');
17877
17951
  resolve(null);
@@ -17913,10 +17987,54 @@ var getCityLocationByAMap = /*#__PURE__*/function () {
17913
17987
  var lat = res.position[1].toString();
17914
17988
  var result = {
17915
17989
  longitude: lng.toString(),
17916
- latitude: lat.toString()
17990
+ latitude: lat.toString(),
17991
+ address: '',
17992
+ poiname: '',
17993
+ regionid: '',
17994
+ country: '',
17995
+ province: '',
17996
+ city: '',
17997
+ district: '',
17998
+ street: '',
17999
+ number: '',
18000
+ detailaddr: '',
18001
+ poiid: '',
18002
+ poitypename: '',
18003
+ poitypecode: '',
18004
+ phonenumber: '',
18005
+ signboard: '',
18006
+ maptype: "amap"
17917
18007
  };
17918
18008
  console.log("getCityLocationByAMap success: ".concat(JSON.stringify(result)));
17919
- resolve(result);
18009
+ // 通过经纬度获取详细地址信息
18010
+ getAddressDetailByAMap({
18011
+ longitude: lng.toString(),
18012
+ latitude: lat.toString()
18013
+ }).then(function (addrssDetail) {
18014
+ if (addrssDetail) {
18015
+ result.address = addrssDetail.addressDetail.address;
18016
+ result.poiname = addrssDetail.addressDetail.poiname;
18017
+ result.regionid = addrssDetail.addressDetail.regionid;
18018
+ result.country = addrssDetail.addressDetail.country;
18019
+ result.province = addrssDetail.addressDetail.province;
18020
+ result.city = addrssDetail.addressDetail.city;
18021
+ result.district = addrssDetail.addressDetail.district;
18022
+ result.street = addrssDetail.addressDetail.street;
18023
+ result.number = addrssDetail.addressDetail.number;
18024
+ result.detailaddr = addrssDetail.addressDetail.detailaddr;
18025
+ result.poiid = addrssDetail.addressDetail.poiid;
18026
+ result.poitypename = addrssDetail.addressDetail.poitypename;
18027
+ result.poitypecode = addrssDetail.addressDetail.poitypecode;
18028
+ result.phonenumber = addrssDetail.addressDetail.phonenumber;
18029
+ result.signboard = addrssDetail.addressDetail.signboard;
18030
+ }
18031
+ console.log("getLocationByAMap success: ".concat(JSON.stringify(result)));
18032
+ resolve(result);
18033
+ })["catch"](function (err) {
18034
+ console.error(err);
18035
+ console.error('getLocationByAMap fail');
18036
+ resolve(null);
18037
+ });
17920
18038
  } else {
17921
18039
  console.error('getCityLocationByAMap fail');
17922
18040
  resolve(null);
@@ -17977,16 +18095,111 @@ var getAddressByAMap = /*#__PURE__*/function () {
17977
18095
  return _ref8.apply(this, arguments);
17978
18096
  };
17979
18097
  }();
17980
- // 腾讯ip定位:通过终端设备IP地址获取其当前所在地理位置,精确到市级,常用于显示当地城市天气预报、初始化用户城市等非精确定位场景。
17981
- var getIPLocationByTMap = /*#__PURE__*/function () {
17982
- var _ref9 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee9(ip) {
18098
+ // 高德逆地址解析详细数据
18099
+ var getAddressDetailByAMap = /*#__PURE__*/function () {
18100
+ var _ref9 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee9(position) {
17983
18101
  return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
17984
18102
  while (1) switch (_context9.prev = _context9.next) {
17985
18103
  case 0:
17986
- console.log('getIPLocationByTMap start...');
18104
+ console.log('getAddressDetailByAMap start...');
17987
18105
  return _context9.abrupt("return", new Promise(function (resolve, reject) {
17988
18106
  var _window4;
17989
- if (!((_window4 = window) !== null && _window4 !== void 0 && _window4.TMap)) {
18107
+ if (!((_window4 = window) !== null && _window4 !== void 0 && _window4.AMap)) {
18108
+ console.error('getAddressDetailByAMap fail: AMap is undefinded');
18109
+ resolve(null);
18110
+ return;
18111
+ }
18112
+ if (position) {
18113
+ new window.AMap.Geocoder({
18114
+ radius: 500,
18115
+ extensions: 'all'
18116
+ }).getAddress([position.longitude, position.latitude], function (status, result) {
18117
+ // console.log(status)
18118
+ // console.log(result)
18119
+ if (status === 'complete' && result.info === 'OK' && result !== null && result !== void 0 && result.regeocode) {
18120
+ console.log("getAddressByAMap success:", result.regeocode);
18121
+ var addressComponent = result.regeocode.addressComponent || {};
18122
+ // 确保 country 字段被正确获取
18123
+ // 直接从高德地图 API 返回的数据中获取 country 字段
18124
+ var country = addressComponent.country || '';
18125
+ var aois = result.regeocode.aois || [];
18126
+ var pois = result.regeocode.pois || [];
18127
+ if (Array.isArray(addressComponent.city)) {
18128
+ addressComponent.city = addressComponent.city.join(',');
18129
+ }
18130
+ var street = addressComponent.street || (addressComponent.streetNumber && isObject$4(addressComponent.streetNumber) ? addressComponent.streetNumber.street : '');
18131
+ var number = addressComponent.streetNumber && isObject$4(addressComponent.streetNumber) ? addressComponent.streetNumber.number : addressComponent.streetNumber || '';
18132
+ if (Array.isArray(street)) {
18133
+ street = street.join(',');
18134
+ }
18135
+ if (Array.isArray(number)) {
18136
+ number = number.join(',');
18137
+ }
18138
+ var poiname = aois && aois[0] && aois[0].name || '';
18139
+ var detailAddr = street + number + poiname || '';
18140
+ var address = (addressComponent.province || '') + (addressComponent.city || '') + (addressComponent.district || '') + (detailAddr || '');
18141
+ var tmpFullDistrinct = (addressComponent.province || '') + (addressComponent.city || '') + (addressComponent.district || '');
18142
+ if (!address.endsWith(poiname)) {
18143
+ address = address + poiname;
18144
+ }
18145
+ var selectedDetailAddr = detailAddr || '';
18146
+ // 去除前面的行政区域
18147
+ if (selectedDetailAddr.startsWith(tmpFullDistrinct)) {
18148
+ selectedDetailAddr = selectedDetailAddr.slice(tmpFullDistrinct.length);
18149
+ }
18150
+ var poiid = pois && pois[0] && pois[0].id;
18151
+ var poitypename = pois && pois[0] && pois[0].type;
18152
+ var addressDetail = {
18153
+ regeocode: result.regeocode,
18154
+ addressDetail: {
18155
+ longitude: position.longitude,
18156
+ latitude: position.latitude,
18157
+ address: address || '',
18158
+ poiname: poiname || '',
18159
+ regionid: addressComponent.adcode || '',
18160
+ country: country || '',
18161
+ province: addressComponent.province || '',
18162
+ city: addressComponent.city || '',
18163
+ district: addressComponent.district || addressComponent.township || '',
18164
+ street: street || '',
18165
+ number: number || '',
18166
+ detailaddr: selectedDetailAddr || '',
18167
+ poiid: poiid || '',
18168
+ poitypename: poitypename || '',
18169
+ poitypecode: '',
18170
+ phonenumber: getPoiPhoneNumber(pois && pois[0] && pois[0].tel),
18171
+ signboard: '',
18172
+ maptype: 'amap'
18173
+ }
18174
+ };
18175
+ resolve(addressDetail);
18176
+ } else {
18177
+ console.error("getAddressByAMap fail: status = ".concat(status, ", result = ").concat(result));
18178
+ resolve(null);
18179
+ }
18180
+ });
18181
+ }
18182
+ }));
18183
+ case 2:
18184
+ case "end":
18185
+ return _context9.stop();
18186
+ }
18187
+ }, _callee9);
18188
+ }));
18189
+ return function getAddressDetailByAMap(_x6) {
18190
+ return _ref9.apply(this, arguments);
18191
+ };
18192
+ }();
18193
+ // 腾讯ip定位:通过终端设备IP地址获取其当前所在地理位置,精确到市级,常用于显示当地城市天气预报、初始化用户城市等非精确定位场景。
18194
+ var getIPLocationByTMap = /*#__PURE__*/function () {
18195
+ var _ref10 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee10(ip) {
18196
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
18197
+ while (1) switch (_context10.prev = _context10.next) {
18198
+ case 0:
18199
+ console.log('getIPLocationByTMap start...');
18200
+ return _context10.abrupt("return", new Promise(function (resolve, reject) {
18201
+ var _window5;
18202
+ if (!((_window5 = window) !== null && _window5 !== void 0 && _window5.TMap)) {
17990
18203
  console.error('getIPLocationByTMap fail: TMap is undefinded');
17991
18204
  resolve(null);
17992
18205
  return;
@@ -18011,24 +18224,24 @@ var getIPLocationByTMap = /*#__PURE__*/function () {
18011
18224
  }));
18012
18225
  case 2:
18013
18226
  case "end":
18014
- return _context9.stop();
18227
+ return _context10.stop();
18015
18228
  }
18016
- }, _callee9);
18229
+ }, _callee10);
18017
18230
  }));
18018
- return function getIPLocationByTMap(_x6) {
18019
- return _ref9.apply(this, arguments);
18231
+ return function getIPLocationByTMap(_x7) {
18232
+ return _ref10.apply(this, arguments);
18020
18233
  };
18021
18234
  }();
18022
18235
  // 腾讯逆地址解析
18023
18236
  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) {
18237
+ var _ref11 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee11(position) {
18238
+ return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
18239
+ while (1) switch (_context11.prev = _context11.next) {
18027
18240
  case 0:
18028
18241
  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)) {
18242
+ return _context11.abrupt("return", new Promise(function (resolve, reject) {
18243
+ var _window6;
18244
+ if (!((_window6 = window) !== null && _window6 !== void 0 && _window6.TMap)) {
18032
18245
  console.error('getAddressByTMap fail: TMap is undefinded');
18033
18246
  resolve('');
18034
18247
  return;
@@ -18055,41 +18268,41 @@ var getAddressByTMap = /*#__PURE__*/function () {
18055
18268
  }));
18056
18269
  case 2:
18057
18270
  case "end":
18058
- return _context10.stop();
18271
+ return _context11.stop();
18059
18272
  }
18060
- }, _callee10);
18273
+ }, _callee11);
18061
18274
  }));
18062
- return function getAddressByTMap(_x7) {
18063
- return _ref10.apply(this, arguments);
18275
+ return function getAddressByTMap(_x8) {
18276
+ return _ref11.apply(this, arguments);
18064
18277
  };
18065
18278
  }();
18066
18279
  // 百度浏览器定位
18067
18280
  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) {
18281
+ var _ref12 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee13() {
18282
+ return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
18283
+ while (1) switch (_context13.prev = _context13.next) {
18071
18284
  case 0:
18072
18285
  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)) {
18286
+ return _context13.abrupt("return", new Promise(function (resolve, reject) {
18287
+ var _window7;
18288
+ if (!((_window7 = window) !== null && _window7 !== void 0 && _window7.BMap)) {
18076
18289
  console.error('getLocationByBMap fail: BMap is undefinded');
18077
18290
  resolve(null);
18078
18291
  return;
18079
18292
  }
18080
18293
  new window.BMap.Geolocation().getCurrentPosition( /*#__PURE__*/function () {
18081
- var _ref12 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee11(res) {
18294
+ var _ref13 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee12(res) {
18082
18295
  var lng, lat, result;
18083
- return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
18084
- while (1) switch (_context11.prev = _context11.next) {
18296
+ return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
18297
+ while (1) switch (_context12.prev = _context12.next) {
18085
18298
  case 0:
18086
18299
  if (res) {
18087
- _context11.next = 4;
18300
+ _context12.next = 4;
18088
18301
  break;
18089
18302
  }
18090
18303
  console.error('getLocationByBMap fail');
18091
18304
  resolve(null);
18092
- return _context11.abrupt("return");
18305
+ return _context12.abrupt("return");
18093
18306
  case 4:
18094
18307
  // 初始化已经指定 window.BMap.coordType = 'BMAP_COORD_GCJ02' 定位返回的定位信息,外层[latitude,longitude]依然是BD09,然后point里面的是GCJ02
18095
18308
  // {
@@ -18132,12 +18345,12 @@ var getLocationByBMap = /*#__PURE__*/function () {
18132
18345
  resolve(result);
18133
18346
  case 9:
18134
18347
  case "end":
18135
- return _context11.stop();
18348
+ return _context12.stop();
18136
18349
  }
18137
- }, _callee11);
18350
+ }, _callee12);
18138
18351
  }));
18139
- return function (_x8) {
18140
- return _ref12.apply(this, arguments);
18352
+ return function (_x9) {
18353
+ return _ref13.apply(this, arguments);
18141
18354
  };
18142
18355
  }(), {
18143
18356
  enableHighAccuracy: true
@@ -18145,49 +18358,49 @@ var getLocationByBMap = /*#__PURE__*/function () {
18145
18358
  }));
18146
18359
  case 2:
18147
18360
  case "end":
18148
- return _context12.stop();
18361
+ return _context13.stop();
18149
18362
  }
18150
- }, _callee12);
18363
+ }, _callee13);
18151
18364
  }));
18152
18365
  return function getLocationByBMap() {
18153
- return _ref11.apply(this, arguments);
18366
+ return _ref12.apply(this, arguments);
18154
18367
  };
18155
18368
  }();
18156
18369
  // 百度城市定位
18157
18370
  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) {
18371
+ var _ref14 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee15() {
18372
+ return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
18373
+ while (1) switch (_context15.prev = _context15.next) {
18161
18374
  case 0:
18162
18375
  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)) {
18376
+ return _context15.abrupt("return", new Promise(function (resolve, reject) {
18377
+ var _window8;
18378
+ if (!((_window8 = window) !== null && _window8 !== void 0 && _window8.BMap)) {
18166
18379
  console.error('getCityLocationByBMap fail: BMap is undefinded');
18167
18380
  resolve(null);
18168
18381
  return;
18169
18382
  }
18170
18383
  new window.BMap.LocalCity().get( /*#__PURE__*/function () {
18171
- var _ref14 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee13(res) {
18384
+ var _ref15 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee14(res) {
18172
18385
  var lng, lat, point, result;
18173
- return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
18174
- while (1) switch (_context13.prev = _context13.next) {
18386
+ return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
18387
+ while (1) switch (_context14.prev = _context14.next) {
18175
18388
  case 0:
18176
18389
  // console.log(res)
18177
18390
  // debugger
18178
18391
  lng = res.center.lng.toString();
18179
18392
  lat = res.center.lat.toString();
18180
18393
  if (!(lng && lat)) {
18181
- _context13.next = 11;
18394
+ _context14.next = 11;
18182
18395
  break;
18183
18396
  }
18184
- _context13.next = 5;
18397
+ _context14.next = 5;
18185
18398
  return BMapTransformBD09ToGCJ02Points([{
18186
18399
  lng: lng,
18187
18400
  lat: lat
18188
18401
  }]);
18189
18402
  case 5:
18190
- point = _context13.sent;
18403
+ point = _context14.sent;
18191
18404
  // console.log(point)
18192
18405
  // debugger
18193
18406
  result = {
@@ -18196,61 +18409,61 @@ var getCityLocationByBMap = /*#__PURE__*/function () {
18196
18409
  };
18197
18410
  console.log("getCityLocationByBMap success: ".concat(JSON.stringify(result)));
18198
18411
  resolve(result);
18199
- _context13.next = 13;
18412
+ _context14.next = 13;
18200
18413
  break;
18201
18414
  case 11:
18202
18415
  console.error('getCityLocationByBMap fail');
18203
18416
  resolve(null);
18204
18417
  case 13:
18205
18418
  case "end":
18206
- return _context13.stop();
18419
+ return _context14.stop();
18207
18420
  }
18208
- }, _callee13);
18421
+ }, _callee14);
18209
18422
  }));
18210
- return function (_x9) {
18211
- return _ref14.apply(this, arguments);
18423
+ return function (_x10) {
18424
+ return _ref15.apply(this, arguments);
18212
18425
  };
18213
18426
  }());
18214
18427
  }));
18215
18428
  case 2:
18216
18429
  case "end":
18217
- return _context14.stop();
18430
+ return _context15.stop();
18218
18431
  }
18219
- }, _callee14);
18432
+ }, _callee15);
18220
18433
  }));
18221
18434
  return function getCityLocationByBMap() {
18222
- return _ref13.apply(this, arguments);
18435
+ return _ref14.apply(this, arguments);
18223
18436
  };
18224
18437
  }();
18225
18438
  // 百度逆地址解析
18226
18439
  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) {
18440
+ var _ref16 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee17(position) {
18441
+ return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
18442
+ while (1) switch (_context17.prev = _context17.next) {
18230
18443
  case 0:
18231
18444
  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;
18445
+ return _context17.abrupt("return", new Promise( /*#__PURE__*/function () {
18446
+ var _ref17 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee16(resolve, reject) {
18447
+ var _window9;
18235
18448
  var point;
18236
- return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
18237
- while (1) switch (_context15.prev = _context15.next) {
18449
+ return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
18450
+ while (1) switch (_context16.prev = _context16.next) {
18238
18451
  case 0:
18239
- if ((_window8 = window) !== null && _window8 !== void 0 && _window8.BMap) {
18240
- _context15.next = 4;
18452
+ if ((_window9 = window) !== null && _window9 !== void 0 && _window9.BMap) {
18453
+ _context16.next = 4;
18241
18454
  break;
18242
18455
  }
18243
18456
  console.error('getAddressByBmap fail: BMap is undefinded');
18244
18457
  resolve('');
18245
- return _context15.abrupt("return");
18458
+ return _context16.abrupt("return");
18246
18459
  case 4:
18247
18460
  if (position) {
18248
- _context15.next = 8;
18461
+ _context16.next = 8;
18249
18462
  break;
18250
18463
  }
18251
18464
  console.error('getAddressByBmap fail');
18252
18465
  resolve('');
18253
- return _context15.abrupt("return");
18466
+ return _context16.abrupt("return");
18254
18467
  case 8:
18255
18468
  // // 把 GCJ02 转化为百度 BD09 地址
18256
18469
  // const points: any = await transformGCJ02ToBD09Points([{
@@ -18275,104 +18488,104 @@ var getAddressByBmap = /*#__PURE__*/function () {
18275
18488
  });
18276
18489
  case 10:
18277
18490
  case "end":
18278
- return _context15.stop();
18491
+ return _context16.stop();
18279
18492
  }
18280
- }, _callee15);
18493
+ }, _callee16);
18281
18494
  }));
18282
- return function (_x11, _x12) {
18283
- return _ref16.apply(this, arguments);
18495
+ return function (_x12, _x13) {
18496
+ return _ref17.apply(this, arguments);
18284
18497
  };
18285
18498
  }()));
18286
18499
  case 2:
18287
18500
  case "end":
18288
- return _context16.stop();
18501
+ return _context17.stop();
18289
18502
  }
18290
- }, _callee16);
18503
+ }, _callee17);
18291
18504
  }));
18292
- return function getAddressByBmap(_x10) {
18293
- return _ref15.apply(this, arguments);
18505
+ return function getAddressByBmap(_x11) {
18506
+ return _ref16.apply(this, arguments);
18294
18507
  };
18295
18508
  }();
18296
18509
  var getLocationPromise = /*#__PURE__*/function () {
18297
- var _ref17 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee17() {
18298
- var _window9;
18510
+ var _ref18 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee18() {
18511
+ var _window10;
18299
18512
  var isuseiplocation,
18300
18513
  location,
18301
- _args17 = arguments;
18302
- return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
18303
- while (1) switch (_context17.prev = _context17.next) {
18514
+ _args18 = arguments;
18515
+ return _regeneratorRuntime$1().wrap(function _callee18$(_context18) {
18516
+ while (1) switch (_context18.prev = _context18.next) {
18304
18517
  case 0:
18305
- isuseiplocation = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : false;
18518
+ isuseiplocation = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : false;
18306
18519
  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;
18520
+ if (!((_window10 = window) !== null && _window10 !== void 0 && (_window10 = _window10.Native) !== null && _window10 !== void 0 && _window10.getLocation)) {
18521
+ _context18.next = 6;
18309
18522
  break;
18310
18523
  }
18311
- _context17.next = 5;
18524
+ _context18.next = 5;
18312
18525
  return getLocationByNative();
18313
18526
  case 5:
18314
- location = _context17.sent;
18527
+ location = _context18.sent;
18315
18528
  case 6:
18316
18529
  if (location) {
18317
- _context17.next = 31;
18530
+ _context18.next = 31;
18318
18531
  break;
18319
18532
  }
18320
18533
  if (!(mapService.type === 'amap')) {
18321
- _context17.next = 17;
18534
+ _context18.next = 17;
18322
18535
  break;
18323
18536
  }
18324
- _context17.next = 10;
18537
+ _context18.next = 10;
18325
18538
  return getLocationByAMap();
18326
18539
  case 10:
18327
- location = _context17.sent;
18540
+ location = _context18.sent;
18328
18541
  if (!(!location && isuseiplocation)) {
18329
- _context17.next = 15;
18542
+ _context18.next = 15;
18330
18543
  break;
18331
18544
  }
18332
- _context17.next = 14;
18545
+ _context18.next = 14;
18333
18546
  return getCityLocationByAMap();
18334
18547
  case 14:
18335
- location = _context17.sent;
18548
+ location = _context18.sent;
18336
18549
  case 15:
18337
- _context17.next = 31;
18550
+ _context18.next = 31;
18338
18551
  break;
18339
18552
  case 17:
18340
18553
  if (!(mapService.type === 'tencent' && isuseiplocation)) {
18341
- _context17.next = 23;
18554
+ _context18.next = 23;
18342
18555
  break;
18343
18556
  }
18344
- _context17.next = 20;
18557
+ _context18.next = 20;
18345
18558
  return getIPLocationByTMap();
18346
18559
  case 20:
18347
- location = _context17.sent;
18348
- _context17.next = 31;
18560
+ location = _context18.sent;
18561
+ _context18.next = 31;
18349
18562
  break;
18350
18563
  case 23:
18351
18564
  if (!(mapService.type === 'baidu')) {
18352
- _context17.next = 31;
18565
+ _context18.next = 31;
18353
18566
  break;
18354
18567
  }
18355
- _context17.next = 26;
18568
+ _context18.next = 26;
18356
18569
  return getLocationByBMap();
18357
18570
  case 26:
18358
- location = _context17.sent;
18571
+ location = _context18.sent;
18359
18572
  if (!(!location && isuseiplocation)) {
18360
- _context17.next = 31;
18573
+ _context18.next = 31;
18361
18574
  break;
18362
18575
  }
18363
- _context17.next = 30;
18576
+ _context18.next = 30;
18364
18577
  return getCityLocationByBMap();
18365
18578
  case 30:
18366
- location = _context17.sent;
18579
+ location = _context18.sent;
18367
18580
  case 31:
18368
18581
  if (location) {
18369
- _context17.next = 35;
18582
+ _context18.next = 35;
18370
18583
  break;
18371
18584
  }
18372
- _context17.next = 34;
18585
+ _context18.next = 34;
18373
18586
  return getLocationByNavigator();
18374
18587
  case 34:
18375
- location = _context17.sent;
18588
+ location = _context18.sent;
18376
18589
  case 35:
18377
18590
  // location = null
18378
18591
  // 开发模式下为了方便测试提供虚拟定位
@@ -18396,30 +18609,30 @@ var getLocationPromise = /*#__PURE__*/function () {
18396
18609
  // }
18397
18610
  // }
18398
18611
  if (!(location && !location.address)) {
18399
- _context17.next = 43;
18612
+ _context18.next = 43;
18400
18613
  break;
18401
18614
  }
18402
- _context17.next = 39;
18615
+ _context18.next = 39;
18403
18616
  return getAddress(location);
18404
18617
  case 39:
18405
- _context17.t0 = _context17.sent;
18406
- if (_context17.t0) {
18407
- _context17.next = 42;
18618
+ _context18.t0 = _context18.sent;
18619
+ if (_context18.t0) {
18620
+ _context18.next = 42;
18408
18621
  break;
18409
18622
  }
18410
- _context17.t0 = '经纬度获取成功,但地址获取失败。';
18623
+ _context18.t0 = '经纬度获取成功,但地址获取失败。';
18411
18624
  case 42:
18412
- location.address = _context17.t0;
18625
+ location.address = _context18.t0;
18413
18626
  case 43:
18414
- return _context17.abrupt("return", location);
18627
+ return _context18.abrupt("return", location);
18415
18628
  case 44:
18416
18629
  case "end":
18417
- return _context17.stop();
18630
+ return _context18.stop();
18418
18631
  }
18419
- }, _callee17);
18632
+ }, _callee18);
18420
18633
  }));
18421
18634
  return function getLocationPromise() {
18422
- return _ref17.apply(this, arguments);
18635
+ return _ref18.apply(this, arguments);
18423
18636
  };
18424
18637
  }();
18425
18638
  // WGS84 GCJ-02 BD-09 坐标系
@@ -18429,104 +18642,104 @@ function getLocation() {
18429
18642
  return _getLocation.apply(this, arguments);
18430
18643
  } // 逆地址解析
18431
18644
  function _getLocation() {
18432
- _getLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee20() {
18645
+ _getLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee21() {
18433
18646
  var isuseiplocation,
18434
18647
  locationRes,
18435
- _args20 = arguments;
18436
- return _regeneratorRuntime$1().wrap(function _callee20$(_context20) {
18437
- while (1) switch (_context20.prev = _context20.next) {
18648
+ _args21 = arguments;
18649
+ return _regeneratorRuntime$1().wrap(function _callee21$(_context21) {
18650
+ while (1) switch (_context21.prev = _context21.next) {
18438
18651
  case 0:
18439
- isuseiplocation = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : false;
18440
- _context20.next = 3;
18652
+ isuseiplocation = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : false;
18653
+ _context21.next = 3;
18441
18654
  return mapService.init();
18442
18655
  case 3:
18443
18656
  if (!(datetime && Date.now() - datetime <= cachetime && lastLocation && !runing)) {
18444
- _context20.next = 5;
18657
+ _context21.next = 5;
18445
18658
  break;
18446
18659
  }
18447
- return _context20.abrupt("return", cloneDeep$1(lastLocation));
18660
+ return _context21.abrupt("return", cloneDeep$1(lastLocation));
18448
18661
  case 5:
18449
18662
  if (!(runing && locationPromise)) {
18450
- _context20.next = 7;
18663
+ _context21.next = 7;
18451
18664
  break;
18452
18665
  }
18453
- return _context20.abrupt("return", locationPromise);
18666
+ return _context21.abrupt("return", locationPromise);
18454
18667
  case 7:
18455
18668
  // console.log('runing')
18456
18669
  runing = true;
18457
18670
  locationPromise = getLocationPromise(isuseiplocation);
18458
- _context20.next = 11;
18671
+ _context21.next = 11;
18459
18672
  return locationPromise;
18460
18673
  case 11:
18461
- locationRes = _context20.sent;
18674
+ locationRes = _context21.sent;
18462
18675
  runing = false;
18463
18676
  if (locationRes) {
18464
18677
  datetime = Date.now();
18465
18678
  lastLocation = locationRes;
18466
18679
  }
18467
- return _context20.abrupt("return", locationRes);
18680
+ return _context21.abrupt("return", locationRes);
18468
18681
  case 15:
18469
18682
  case "end":
18470
- return _context20.stop();
18683
+ return _context21.stop();
18471
18684
  }
18472
- }, _callee20);
18685
+ }, _callee21);
18473
18686
  }));
18474
18687
  return _getLocation.apply(this, arguments);
18475
18688
  }
18476
18689
  var getAddress = /*#__PURE__*/function () {
18477
- var _ref18 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee18(position) {
18690
+ var _ref19 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee19(position) {
18478
18691
  var address;
18479
- return _regeneratorRuntime$1().wrap(function _callee18$(_context18) {
18480
- while (1) switch (_context18.prev = _context18.next) {
18692
+ return _regeneratorRuntime$1().wrap(function _callee19$(_context19) {
18693
+ while (1) switch (_context19.prev = _context19.next) {
18481
18694
  case 0:
18482
- _context18.next = 2;
18695
+ _context19.next = 2;
18483
18696
  return mapService.init();
18484
18697
  case 2:
18485
18698
  address = '';
18486
18699
  if (address) {
18487
- _context18.next = 20;
18700
+ _context19.next = 20;
18488
18701
  break;
18489
18702
  }
18490
18703
  if (!(mapService.type === 'amap')) {
18491
- _context18.next = 10;
18704
+ _context19.next = 10;
18492
18705
  break;
18493
18706
  }
18494
- _context18.next = 7;
18707
+ _context19.next = 7;
18495
18708
  return getAddressByAMap(position);
18496
18709
  case 7:
18497
- address = _context18.sent;
18498
- _context18.next = 20;
18710
+ address = _context19.sent;
18711
+ _context19.next = 20;
18499
18712
  break;
18500
18713
  case 10:
18501
18714
  if (!(mapService.type === 'tencent')) {
18502
- _context18.next = 16;
18715
+ _context19.next = 16;
18503
18716
  break;
18504
18717
  }
18505
- _context18.next = 13;
18718
+ _context19.next = 13;
18506
18719
  return getAddressByTMap(position);
18507
18720
  case 13:
18508
- address = _context18.sent;
18509
- _context18.next = 20;
18721
+ address = _context19.sent;
18722
+ _context19.next = 20;
18510
18723
  break;
18511
18724
  case 16:
18512
18725
  if (!(mapService.type === 'baidu')) {
18513
- _context18.next = 20;
18726
+ _context19.next = 20;
18514
18727
  break;
18515
18728
  }
18516
- _context18.next = 19;
18729
+ _context19.next = 19;
18517
18730
  return getAddressByBmap(position);
18518
18731
  case 19:
18519
- address = _context18.sent;
18732
+ address = _context19.sent;
18520
18733
  case 20:
18521
- return _context18.abrupt("return", address);
18734
+ return _context19.abrupt("return", address);
18522
18735
  case 21:
18523
18736
  case "end":
18524
- return _context18.stop();
18737
+ return _context19.stop();
18525
18738
  }
18526
- }, _callee18);
18739
+ }, _callee19);
18527
18740
  }));
18528
- return function getAddress(_x13) {
18529
- return _ref18.apply(this, arguments);
18741
+ return function getAddress(_x14) {
18742
+ return _ref19.apply(this, arguments);
18530
18743
  };
18531
18744
  }();
18532
18745
  // const getDistance = async (p1: [number, number], p2: [number, number]) => {
@@ -18535,10 +18748,10 @@ var getAddress = /*#__PURE__*/function () {
18535
18748
  // }
18536
18749
  // 两个经纬度距离计算
18537
18750
  var getDistance = /*#__PURE__*/function () {
18538
- var _ref19 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee19(latlng1, latlng2) {
18751
+ var _ref20 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee20(latlng1, latlng2) {
18539
18752
  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) {
18753
+ return _regeneratorRuntime$1().wrap(function _callee20$(_context20) {
18754
+ while (1) switch (_context20.prev = _context20.next) {
18542
18755
  case 0:
18543
18756
  // console.log(latlng1)
18544
18757
  // console.log(latlng2)
@@ -18553,15 +18766,15 @@ var getDistance = /*#__PURE__*/function () {
18553
18766
  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
18767
  s = s * 6378.137; // EARTH_RADIUS
18555
18768
  s = Math.round(s * 10000) / 10000;
18556
- return _context19.abrupt("return", s * 1000);
18769
+ return _context20.abrupt("return", s * 1000);
18557
18770
  case 12:
18558
18771
  case "end":
18559
- return _context19.stop();
18772
+ return _context20.stop();
18560
18773
  }
18561
- }, _callee19);
18774
+ }, _callee20);
18562
18775
  }));
18563
- return function getDistance(_x14, _x15) {
18564
- return _ref19.apply(this, arguments);
18776
+ return function getDistance(_x15, _x16) {
18777
+ return _ref20.apply(this, arguments);
18565
18778
  };
18566
18779
  }();
18567
18780
 
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.1",
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
+ }