目录
执行此代码 : npm install vue-jsonp --save
import { VueJsonp } from 'vue-jsonp'
Vue.use(VueJsonp)

这里必须配置,不可以忘,否则会出现报错
- 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
-
- })
上方代码涵盖ubi-app小程序端的地理位置配置
https://apis.map.qq.com/ws/geocoder/v1/ (let url的地址由来)