"use strict";
const common_vendor = require("../vendor.js");
function getMapAddress() {
  const TIANDITU_KEY = "4ce26ecef55ae1ec47910a72a098efc0";
  return new Promise((resolve, reject) => {
    common_vendor.index.getLocation({
      type: "wgs84",
      altitude: true,
      isHighAccuracy: true,
      success(res) {
        console.log(res, "经纬度");
        const url = `https://api.tianditu.gov.cn/geocoder?postStr={'lon':${res.longitude},'lat':${res.latitude},'ver':2}&type=geocode&tk=${TIANDITU_KEY}`;
        common_vendor.index.request({
          url,
          method: "GET",
          success(res2) {
            var _a, _b;
            resolve({ address: ((_b = (_a = res2 == null ? void 0 : res2.data) == null ? void 0 : _a.result) == null ? void 0 : _b.formatted_address) || "" });
            console.log(res2, "address");
          },
          fail(res2) {
            resolve({ address: "拒绝定位" });
            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);
      }
    });
  });
}
exports.getMapAddress = getMapAddress;
