uniapp腾讯地图逆地址解析报Access to XMLHttpRequest at ‘https://apis.map.qq.com/ws/geocoder/v1/?key=M7VBZ- 错误解决
这个是因为请求腾讯地图api导致跨域错误解决办法就是使用uniapp终端安装vue-jsonp。
·
这个是因为请求腾讯地图api导致跨域错误解决办法就是使用uniapp终端安装vue-jsonp
import {
jsonp
} from 'vue-jsonp'; //安装完成组件引用
//使用
jumpMap() {
let that = this;
uni.chooseLocation({
success: function(res) {
that.cascade = res.address;
that.lat = res.latitude;
that.lng = res.longitude;
let url = 'https://apis.map.qq.com/ws/geocoder/v1/';
jsonp(url, {
key: 'M7VBZ-ONPCM-TCB63-6RKVK-UCMMO-65FTP',
location: res.latitude + ',' + res.longitude,
output: 'jsonp'
}).then(res => {
console.log('jsonp', res.result.address_component);
let {
province,
city,
district
} = res.result.address_component;
that.province = province;
that.city = city;
that.area = district;
console.log(province, city, district);
})
}
});
},
//主要是这段代码
let url = 'https://apis.map.qq.com/ws/geocoder/v1/';
jsonp(url, {
key: 'M7VBZ-ONPCM-TCB63-6RKVK-UCMMO-65FTP',
location: res.latitude + ',' + res.longitude,
output: 'jsonp'
}).then(res => {
console.log('jsonp', res.result.address_component);
let {
province,
city,
district
} = res.result.address_component;
that.province = province;
that.city = city;
that.area = district;
console.log(province, city, district);
})
更多推荐
已为社区贡献4条内容
所有评论(0)