参考文档:https://blog.csdn.net/qq_42231156/article/details/89764301
理解:
onLoad() {
// 位置信息的获取
var _this=this;
uni.getLocation({
type: 'wgs84',
success (res) {
console.log("你当前经纬度是:")
console.log(res)
let latitude,longitude;
latitude = res.latitude.toString();
longitude = res.longitude.toString();
uni.request({
header:{
"Content-Type": "application/text"
},
url:'http://apis.map.qq.com/ws/geocoder/v1/?location='+latitude+','+longitude+'&key=MVGBZ-R2U3U-W5CVY-2PQID-AT4VZ-PDF35',
success(re) {
console.log("中文位置");
console.log(re);
console.log(re.data.result.address);
_this.my_loc = re.data.result.address;
if(re.statusCode===200){
console.log("获取中文街道地理位置成功")
}else{
console.log("获取信息失败,请重试!")
}
}
});
}
});
},
微信编译报错:
在manifest.json的源码视图中配置:配置appid和地理位置
"mp-weixin": { /* 小程序特有相关 */
"appid": "", //需要配置appid
"setting": {
"urlCheck": false
},
"usingComponents": true,
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
}
}
位置选择:
// 选择位置
get_loc(e){
var _this=this;
uni.chooseLocation({
success: (res) => {
_this.my_loc = res.address;
}
})
},