t-comm
Version:
专业、稳定、纯粹的工具库
40 lines (37 loc) • 1.25 kB
JavaScript
import { LocationFlag } from '../location-interface.mjs';
var TencentMapApiLocation = /** @class */function () {
function TencentMapApiLocation() {}
TencentMapApiLocation.prototype.getLocation = function () {
return new Promise(function (resolve, reject) {
// @ts-ignore
wx.getLocation({
type: 'gcj02',
success: function success(res) {
var location = {
lat: parseFloat("".concat(res.latitude)),
lng: parseFloat("".concat(res.longitude))
};
TencentMapApiLocation.lastLocation = location;
resolve({
location: location,
flag: LocationFlag.LocationSuccess
});
},
fail: function fail(error) {
console.log('MiniProgramLocation', error);
// 频繁调用导致失败,返回最后一次location
if (error.errMsg && error.errMsg.indexOf('频繁调用') > -1) {
resolve({
location: TencentMapApiLocation.lastLocation,
flag: LocationFlag.LocationSuccess
});
return;
}
reject();
}
});
});
};
return TencentMapApiLocation;
}();
export { TencentMapApiLocation as default };