一、申请密钥key
- https://lbs.qq.com/ 腾讯申请地址,没注册的先注册,然后进入控制台
- 创建应用,添加key

- uniapp授权

- 在腾讯地图上下载微信小程序javaScript SDK放入项目里,地址https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/jsSdkOverview

- 引入项目,路径自行改

二、项目使用代码
提示,引入可能会报错,修改如下

代码使用
import QQMapWx from '@/js_sdk/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.js'
const qqmapSdk = new QQMapWx({
key: '*********'
});
getAuthorize() {
uni.authorize({
scope: 'scope.userLocation',
success: (res) => {
this.getLocation('gcj02');
},
fail: (err) => {
uni.showModal({
content: '需要授权位置信息',
confirmText: '确认授权'
}).then(res => {
if (res['confirm']) {
uni.openSetting({
success: res => {
if (res.authSetting['scope.userLocation']) {
uni.showToast({
title: '授权成功',
icon: 'none'
})
} else {
uni.showToast({
title: '授权失败',
icon: 'none'
})
}
this.getLocation('gcj02')
}
})
}
if (res['cancel']) {
this.getLocation('gcj02')
}
})
}
})
},
getLocation(type) {
uni.getLocation({
type: type,
success: (res) => {
const {
latitude,
longitude
} = res;
qqmapSdk.reverseGeocoder({
location: latitude ? `${latitude},${longitude }` : '',
sig: '**************',
success: (val) => {
console.log('这就是要获取的当前所在城市的相关信息', val)
},
fail: (err) => {
console.log('获取城市失败')
}
})
},
fail: (err) => {
uni.stopPullDownRefresh();
if (err.errMsg === 'getLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF' || err
.errMsg === 'getLocation:fail system permission denied') {
uni.showModal({
content: '请开启手机定位服务',
showCancel: false
})
} else if (err.errMsg === 'getLocation:fail:system permission denied') {
uni.showModal({
content: '请给微信开启定位权限',
showCancel: false
})
}
}
})
},
over