t-comm
Version:
专业、稳定、纯粹的工具库
71 lines (68 loc) • 2.6 kB
JavaScript
import axios from 'axios';
import { getAreaCode } from '../../city/city.mjs';
import { get } from '../../lodash-mini/get.mjs';
import '@babel/runtime/helpers/typeof';
import '../../tslib.es6-096fffdd.js';
import { tencentMapConfig, LocationFlag } from '../location-interface.mjs';
import '../../city/data.mjs';
// 用腾讯地图api通过IP获取lbs地址
var TencentMapApiLocation = /** @class */function () {
function TencentMapApiLocation() {}
// 用经纬度逆解析出省市信息
TencentMapApiLocation.getAreaInfoByLatAndLng = function (lat, lng) {
return new Promise(function (resolve, reject) {
axios.get("https://apis.map.qq.com/ws/geocoder/v1/?location=".concat(lat, ",").concat(lng, "&key=").concat(tencentMapConfig.GEO_KEY_PLUS)).then(function (res) {
if (res.data) {
var data = res.data;
data.city = get(data, 'result.ad_info.city');
data.province = get(data, 'result.ad_info.province');
var retList = getAreaCode(data.province, data.city);
if (retList.length > 1) {
data.provinceId = retList[0] || 0;
data.cityId = retList[1] || 0;
}
resolve(data);
} else {
reject();
}
})["catch"](function (error) {
reject(error);
});
});
};
TencentMapApiLocation.prototype.getLocation = function (options) {
return new Promise(function (resolve, reject) {
var _a;
if (!options.fetchLBSRequest) {
reject();
return;
}
(_a = options.fetchLBSRequest) === null || _a === void 0 ? void 0 : _a.call(options).then(function (res) {
// })
// post({ url: '/pmdtrpc.commcgi.tipcgi.tipcgi/GetLBS', showMsgToast: false }).then((res) => {
var result = (res === null || res === void 0 ? void 0 : res.ip_result) || {};
var location = (result === null || result === void 0 ? void 0 : result.location) || {};
if ((location === null || location === void 0 ? void 0 : location.lat) && location.lng) {
var position = {
lat: location.lat,
lng: location.lng,
ip: result.ip,
type: 'ip',
adInfo: result.ad_info
};
resolve({
location: position,
flag: LocationFlag.LocationIpSuccess
});
} else {
reject();
}
})["catch"](function (error) {
console.log('TencentMapApiLocation', error);
reject();
});
});
};
return TencentMapApiLocation;
}();
export { TencentMapApiLocation as default };