参考文档:地理/逆地理编码-基础 API 文档-开发指南-Web服务 API | 高德地图API
/utils/getLoadCity.js
// 调用高德地图获取详细地址 App H5 Wx可调用
const AMapGetLoadCity = (longitude, latitude) => {
const key = "你的key";
return new Promise((resolve, reject) => {
uni.request({
//注意:这里的key值需要高德地图的 web服务生成的key 只有web服务才有逆地理编码
url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" +
longitude +
"," +
latitude +
"&key=" +
key +
"&radius=1000&extensions=all",
}).then((result) => {
let res = result[1]
if (res.statusCode === 200) {
resolve(res.data.regeocode);
} else {
resolve("--");
}
});
});
}
export {
AMapGetLoadCity,
}
页面引用
import { AMapGetLoadCity } from "@/utils/getLoadCity.js";
async mounted() {
let regeocode = await AMapGetLoadCity(114.24779, 22.71991)
console.log("regeocode==", regeocode);
},
控制台打印图