1.安装jsonp
npm install vue-jsonp
2.main.js 引入
import Vue from 'vue'
import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp)
3.举个例子:逆地址解析(坐标转位置信息)
methods:{
getAddresss(lat,lng){
const KEY =XXXXXXXXXXXXXX; //key 秘钥自己申请
let url = 'https://apis.map.qq.com/ws/geocoder/v1?&poi_options=address_format=short&get_poi=0';
let locationdata = lat+','+lng //纬度,经度
this.$jsonp(url,{
key:KEY,
callbackName: 'QQmap',
output:'jsonp',
location:locationdata
})
.then(json => {
let address = json.result.address;
console.log(address) //附近街道地址信息
})
.catch(err => {
console.log(err)
})
}
}