UNPKG

t-comm

Version:

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

68 lines (61 loc) 2.65 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _classCallCheck = require('@babel/runtime/helpers/classCallCheck'); var _createClass = require('@babel/runtime/helpers/createClass'); var city_city = require('../../city/city.js'); var loader_loaderUnity = require('../../loader/loader-unity.js'); var location_locationInterface = require('../location-interface.js'); require('../../city/data.js'); require('../../loader/little-loader.js'); require('../../loader/loader.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck); var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass); // 用腾讯地图sdk获取lbs地址 var TencentMapLocation = /*#__PURE__*/function () { function TencentMapLocation() { _classCallCheck__default["default"](this, TencentMapLocation); } return _createClass__default["default"](TencentMapLocation, [{ key: "getLocation", value: function getLocation(options) { return new Promise(function (resolve, reject) { function geoShowPosition(location) { if (!!location.province && !!location.city) { var retList = city_city.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: location_locationInterface.LocationFlag.LocationSuccess }); } else if (location) { resolve({ location: location, flag: location_locationInterface.LocationFlag.LocationIpSuccess }); } else { reject(); } } function geoShowError() { reject(); } loader_loaderUnity.loader('https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js', function () { // @ts-ignore var geolocation = new window.qq.maps.Geolocation(location_locationInterface.tencentMapConfig.GEO_KEY, location_locationInterface.tencentMapConfig.GEO_REFERER); var tencentMapOptions = { timeout: options.timeout }; geolocation.getLocation(geoShowPosition, geoShowError, tencentMapOptions); }); }); } }]); }(); exports["default"] = TencentMapLocation;