UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

77 lines (70 loc) 2.9 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var axios = require('axios'); var city_city = require('../../city/city.js'); var location_locationInterface = require('../location-interface.js'); var lodashMini_get = require('../../lodash-mini/get.js'); require('../../city/data.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios); // 用腾讯地图api通过IP获取lbs地址 var TencentMapApiLocation = /** @class */function () { function TencentMapApiLocation() {} // 用经纬度逆解析出省市信息 TencentMapApiLocation.getAreaInfoByLatAndLng = function (lat, lng) { return new Promise(function (resolve, reject) { axios__default["default"].get("https://apis.map.qq.com/ws/geocoder/v1/?location=".concat(lat, ",").concat(lng, "&key=").concat(location_locationInterface.tencentMapConfig.GEO_KEY_PLUS)).then(function (res) { if (res.data) { var data = res.data; data.city = lodashMini_get.get(data, 'result.ad_info.city'); data.province = lodashMini_get.get(data, 'result.ad_info.province'); var retList = city_city.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: location_locationInterface.LocationFlag.LocationIpSuccess }); } else { reject(); } })["catch"](function (error) { console.log('TencentMapApiLocation', error); reject(); }); }); }; return TencentMapApiLocation; }(); exports["default"] = TencentMapApiLocation;