**
1.微信小程序先获取getLocationAPI权限
2.manifest.json文件中加上
“permission” : {
“scope.userLocation” : {
“desc” : “你的位置将用于小程序位置接口的效果展示”
}
},
“requiredPrivateInfos” : [ “getLocation” ]
高德
getLocation() {
uni.getLocation({
type: ‘wgs84’,
success: (res) => {
this.latitude = res.latitude
this.longitude = res.longitude
this.reverseGeocode(res.latitude, res.longitude);
},
fail: (err) => {
this.error = err;
console.error(‘定位失败:’, err);
}
});
},
// 逆地理编码函数
reverseGeocode(latitude, longitude) {
const key = 'xxxxx; // 换成你自己的AppKey
const url = https://restapi.amap.com/v3/geocode/regeo?key=${key}&location=${lo