"use strict"; var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; const common_vendor = require("../common/vendor.js"); const utils_commUtils = require("../utils/commUtils.js"); const utils_http = require("../utils/http.js"); const CACHE_KEY = "lastLocation"; const THROTTLE_TIME = 3e4; const getMapDetailAddress = (longitude, latitude) => __async(exports, null, function* () { try { const res = yield utils_http.httpGet("/map/detail", { longitude, latitude }); if (res.code == 200) { return res.data; } return null; } catch (err) { console.error("获取详细地址信息失败:", err); throw err; } }); const getLocation = () => __async(exports, null, function* () { const currentTime = Date.now(); const cachedLocation = common_vendor.index.getStorageSync(CACHE_KEY); if (cachedLocation && currentTime - cachedLocation.time < THROTTLE_TIME) { return cachedLocation.data; } try { const res = yield new Promise((resolve, reject) => { common_vendor.index.getLocation({ type: "gcj02", success: (res2) => { resolve(res2); }, fail: (err) => { reject(err); } }); }); common_vendor.index.setStorageSync(CACHE_KEY, { data: res, time: currentTime // 记录获取位置的时间戳 }); return res; } catch (err) { console.log(err); utils_commUtils.toast("获取位置失败"); throw err; } }); exports.getLocation = getLocation; exports.getMapDetailAddress = getMapDetailAddress; //# sourceMappingURL=mapService.js.map