/*
 * @Descripttion: HJ
 * @Company: 思宏科技
 * @version: v1.0
 * @Author: HJ
 * @Date: 2020-09-29 09:51:26
 * @LastEditors: HJ
 * @LastEditTime: 2021-04-09 20:44:15
 */
//腾讯地图 逆地址解析
const QQMapWX = require("./qqmap-wx-jssdk.js");
// 实例化API核心类
const { tentMapKey = "" } = wx.$env;
// 地图实例
export const qqmapsdk = new QQMapWX({
  key: tentMapKey, // 必填
});

export const reverseGeocoder = () =>
  new Promise((resolve, reject) => {
    qqmapsdk.reverseGeocoder({
      success: function (res) {
        const {
          result: { formatted_addresses, location },
        } = res || {};
        //成功后的回调
        const title = formatted_addresses.recommend;
        wx.setStorageSync("latitude", location.lat);
        wx.setStorageSync("longitude", location.lng);
        // 存储
        wx.setStorageSync("tempLocation", {
          title,
          latitude: location.lat,
          longitude: location.lng,
        });
        resolve({ title });
      },
      fail: function (e) {
        console.log("获取地理位置失败", JSON.stringify(e));
        reject(Error(e));
      },
    });
  });
