46 lines
1.6 KiB
JavaScript
Raw Normal View History

2026-01-30 09:54:46 +08:00
"use strict";
const common_vendor = require("../vendor.js");
2026-07-07 10:06:45 +08:00
function getShowApiAddress() {
const SHOWAPI_APP_KEY = "C59885FE214644168eB4197eFe9a48b9";
2026-01-30 09:54:46 +08:00
return new Promise((resolve, reject) => {
common_vendor.index.getLocation({
2026-07-07 10:06:45 +08:00
type: "wgs84",
2026-01-30 09:54:46 +08:00
altitude: true,
isHighAccuracy: true,
success(res) {
console.log(res, "经纬度");
2026-07-07 10:06:45 +08:00
const url = `https://route.showapi.com/238-3?appKey=${SHOWAPI_APP_KEY}&lng=${res.longitude}&lat=${res.latitude}&from=5`;
2026-01-30 09:54:46 +08:00
common_vendor.index.request({
url,
method: "GET",
success(res2) {
2026-07-07 10:06:45 +08:00
var _a, _b;
2026-01-30 09:54:46 +08:00
console.log(res2, "address");
2026-07-07 10:06:45 +08:00
resolve({ formatted_address: ((_b = (_a = res2 == null ? void 0 : res2.data) == null ? void 0 : _a.showapi_res_body) == null ? void 0 : _b.formatted_address) || "" });
2026-01-30 09:54:46 +08:00
},
fail(res2) {
2026-07-07 10:06:45 +08:00
resolve({ formatted_address: "拒绝定位" });
2026-01-30 09:54:46 +08:00
console.error("获取地址失败:", res2);
common_vendor.index.showModal({
title: "提示",
content: "请先允许定位!",
success: function(res3) {
if (res3.confirm) {
common_vendor.index.openSetting();
console.log("用户点击确定");
} else if (res3.cancel) {
console.log("用户点击取消");
}
}
});
}
});
},
fail(e) {
console.log("拒绝定位", e);
}
});
});
}
2026-07-07 10:06:45 +08:00
exports.getShowApiAddress = getShowApiAddress;