UNPKG

t-comm

Version:

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

54 lines (51 loc) 1.86 kB
import { getAreaCode } from '../../city/city.mjs'; import { loader } from '../../loader/loader-unity.mjs'; import { tencentMapConfig, LocationFlag } from '../location-interface.mjs'; import '../../city/data.mjs'; import '../../tslib.es6-096fffdd.js'; import '../../loader/little-loader.mjs'; import '../../loader/loader.mjs'; // 用腾讯地图sdk获取lbs地址 var TencentMapLocation = /** @class */function () { function TencentMapLocation() {} TencentMapLocation.prototype.getLocation = function (options) { return new Promise(function (resolve, reject) { function geoShowPosition(location) { if (!!location.province && !!location.city) { var retList = getAreaCode(location.province, location.city); if (retList.length > 1) { location.provinceId = retList[0] || 0; location.cityId = retList[1] || 0; } } if (location && location.type !== 'ip') { // 拒绝定位会使用ip地址定位 resolve({ location: location, flag: LocationFlag.LocationSuccess }); } else if (location) { resolve({ location: location, flag: LocationFlag.LocationIpSuccess }); } else { reject(); } } function geoShowError() { reject(); } loader('https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js', function () { // @ts-ignore var geolocation = new window.qq.maps.Geolocation(tencentMapConfig.GEO_KEY, tencentMapConfig.GEO_REFERER); var tencentMapOptions = { timeout: options.timeout }; geolocation.getLocation(geoShowPosition, geoShowError, tencentMapOptions); }); }); }; return TencentMapLocation; }(); export { TencentMapLocation as default };