我使用uniapp开发app,后台接口在网页上测试可以获取到数据,但是我一调用只会返回一个网页的代码,如何解决?
【相关推荐】
地址
https://lbs.qq.com/service/webService/webServiceGuide/webServiceDistance代码
getDistance() {
uni.request({
url: 'https://apis.map.qq.com/ws/distance/v1/matrix', //仅为示例,并非真实接口地址。
method: 'GET',
data: {
mode: 'walking',
from: '39.071510,117.190091',
to: '39.108951,117.279396',
key: '.....' //获取key
},
success: (res) => {
console.log(res);
let hw = res.data.result.rows[0].elements[0].distance; //拿到距离(米)
if (hw && hw !== -1) {
if (hw < 1000) {
hw = hw + 'm';
}
//转换成公里
else {
hw = (hw / 2 / 500).toFixed(2) + 'km'
}
} else {
hw = "距离太近或请刷新重试"
}
console.log(hw);
}
});
}
测试