官方参考文档:
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
}
var QQMapWX = require('../../../page/common/sdk/qqmap-wx-jssdk.js');
var qqmapsdk = new QQMapWX({
key: 'Key'
});
console.log('signin')
const _this = this;
wx.getLocation({
type: 'gcj02',
success: function (res) {
qqmapsdk.reverseGeocoder({
location: {
latitude: res.latitude,
longitude: res.longitude
},
success: function (addressRes) { //成功后的回调
var addressRes = addressRes.result;
console.log( addressRes.address)
},
fail: function (error) {
console.error(error);
},
complete: function (addressRes) {
console.log(addressRes);
}
})
}
})
成功获取到的信息截图
var addressRes = addressRes.result;
var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
var x = parseFloat(addressRes.location.lng);
var y = parseFloat(addressRes.location.lat);
var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
var lng = z * Math.cos(theta) + 0.0065;
var lat = z * Math.sin(theta) + 0.006;
console.log(lng)
console.log(lat)
划重点:发布以后小程序中以下这段函数,会进入fail,获取逆解析失败
qqmapsdk.reverseGeocoder({
location: {
latitude: res.latitude,
longitude: res.longitude
},
success: function (addressRes) { //成功后的回调
var addressRes = addressRes.result;
console.log( addressRes.address)
},
fail: function (error) {
console.error(error);
},
complete: function (addressRes) {
console.log(addressRes);
}
})
解决方案:服务器域名的配置文件中“request合法域名”中需要添加调用的“”
注意了:真机、测试都不会报错,小程序体验版中调试也不会报错,但是,就是会在正式发布的版本中,报错~~~~坑