1、如上图所描述,在微信开发者工具和体验版本上,都可以正确获取到地址,唯独发布上线版本选择不了地址,报错信息如下:
MiniProgramError
result is not defined
ReferenceError: result is not defined
at e.fail (https://usr/app-service.js:11299:1870)
at https://lib/WASubContext.js:2:101623
at https://lib/WASubContext.js:2:101776
2、贴出具体代码,有微信小程序的技术员能帮找一下具体原因吗,万分感谢!
chose_location: function() {
var that = this;
wx.chooseLocation({
success: function(e) {
console.log("选中的地址:"+e.address);
var lon_lat = e.longitude + ',' + e.latitude;
var path = e.address;
var s_region = that.data.region;
var dol_path = '';
var str = path;
var patt = new RegExp("(.*?省)(.*?市)(.*?区)", "g");
var result = patt.exec(str);
if (result == null) {
patt = new RegExp("(.*?省)(.*?市)(.*?市)", "g");
result = patt.exec(str);
if (result == null) {
patt = new RegExp("(.*?省)(.*?市)(.*县)", "g");
result = patt.exec(str);
if (result != null) {
s_region[0] = result[1];
s_region[1] = result[2];
s_region[2] = result[3];
dol_path = path.replace(result[0], '');
}
} else {
s_region[0] = result[1];
s_region[1] = result[2];
s_region[2] = result[3];
dol_path = path.replace(result[0], '');
}
} else {
s_region[0] = result[1];
s_region[1] = result[2];
s_region[2] = result[3];
dol_path = path.replace(result[0], '');
}
var filename = dol_path + e.name;
let addr_detail = filename;
let address_component = '';
locat.getGpsLocation(e.latitude, e.longitude).then((res) => {
address_component = res;
if (address_component) {
s_region[0] = address_component.province;
s_region[1] = address_component.city;
s_region[2] = address_component.district;
addr_detail = filename || address_component.street;
}
that.setData({
region: s_region,
lon_lat: lon_lat,
addr_detail
})
});
if (s_region[0] == '省') {
wx.showToast({
title: '请重新选择省市区',
icon: 'none',
})
}
},
fail: function(e) {
wx.showToast({
title: '地址获取失败',
icon: 'none',
})
console.log('地址获取失败', e)
}
})
},

问题我自己解决了,说一下具体原因和解决方法,给大家一些经验:
1、首先,我腾讯地图用的是别人的key,然后刚才我去腾讯位置服务平台看了一些,这个key是要绑定具体的小程序AppID的,所以千万不要直接使用别人key;
2、其次,我微信小程序服务器域名没有添加腾讯地图的接口域名,需要在request合法域名里添加https://apis.map.qq.com,如下图:
用sourcemap查下报错位置,看着不像你贴出来的代码报的错误