Table of contents
Step 2: Configure and use in mian.js
Step 3: Make relevant configurations in manifest.json
Step 4: Get the latitude and longitude value to get the address
Step 1: Install jsonp
Execute this code: npm install vue-jsonp --save
Step 2: Configure and use in mian.js
import { VueJsonp } from 'vue-jsonp'
Vue.use(VueJsonp)
Step 3: Make relevant configurations in manifest.json
It must be configured here and cannot be forgotten, otherwise an error will appear
Step 4: Get the latitude and longitude value to get the address
uni.getLocation({ //获取当前的地理位置、速度
type: 'gcj02',
highAccuracyExpireTime: 100,
success: (res => {
// console.log('当前位置的经度:' + res.longitude);
// console.log('当前位置的纬度:' + res.latitude);
// #ifdef MP
this.qqmapsdk.reverseGeocoder({
location: {
latitude: res.latitude, //纬度
longitude: res.longitude // 经度
},
success: (req) => {
console.log(req);
this.address = req.result.address
}
})
// #endif
// #ifdef H5
let url = 'https://apis.map.qq.com/ws/geocoder/v1/'
let data = { //模板
location: res.latitude + ',' + res.longitude, //拼接形式
key: '11111', //自己的key
output: 'jsonp',
callback: 'jsonp'
}
this.$jsonp(url, data).then(req => {
if (req.status == 0) {
console.log(req, 'succ') //成功会返回相关信息
this.address = req.result.address
} else {
console.log(req, 'err') //返回失败原因
}
})
// #endif
})
The above code covers the geographic location configuration of the ubi-app applet
uni.getLocation () to obtain the current geographic location, speed
https://apis.map.qq.com/ws/geocoder/v1/ (the address origin of let url)