import Tools from './tools.js'; const amapFile = require('@/common/amap-wx.js') var myAmapFun = new amapFile.AMapWX({key: '01d42bb16e23baca11f1227164a200fd'}); //01d42bb16e23baca11f1227164a200fd使用本人高德 //逆向解析 function getNameByLatLng(latitude,longitude){ return new Promise((resolve,reject)=>{ //未使用微信授权api myAmapFun.getRegeo({ location:longitude+','+latitude, success: function(data){ // console.log("getRegeo data--",data); resolve(data[0]); }, fail: err=> { reject("逆向地址解析错误"); console.log(err) } }) }) } async function chooseLoc(){ return new Promise(async (resolve,reject)=>{ let [cErr,cRes] = await uni.chooseLocation({type:'gcj02'}); if(cErr){ reject(cErr) return; } let {latitude,longitude} = cRes let loc = await getNameByLatLng(latitude,longitude) || {}; // console.log('getNameByLatLng===',loc,loc.regeocodeData.addressComponent.province); if(loc.regeocodeData && loc.regeocodeData.addressComponent){ let {province,city,district,township} = loc.regeocodeData.addressComponent; let address = district+township+loc.desc; resolve({ province, city, area:district, address, latitude, longitude, }) return; } return reject(false); }) } export{ getNameByLatLng, chooseLoc, }