选择 微信小程序 → JavaScriptSDK v1.1版本
解压后复制到小程序项目中;通常放在Utils目录;其中一个是压缩 min 版;使用任意一个都可以
小程序管理后台 → 开发 → 开发管理 → 开发设置 → “服务器域名” 中设置request合法域名,添加https://apis.map.qq.com
// 引入SDK核心类,js文件根据自己业务,位置可自行放置 const QQMapWX = require('../../libs/qqmap-wx-jssdk.js'); const qqmapsdk = new QQMapWX({ key: '申请的key' });
wx.getLocation({ type: 'gcj02', success: res => { const latitude = res.latitude; const longitude = res.longitude; qqmapsdk.reverseGeocoder({ location: { latitude: latitude, longitude: longitude }, success: (res) => { console.log(res); const nation = res.result.address_component.nation; const city = res.result.address_component.city; this.setData({ ulocation:nation+' '+city, isDone:true }) }, fail: (error) => console.error(error), complete: () => console.log('get done') }); }, fail: err => console.log(err), complete: () => console.log('get city done') })
wx.request({ url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=23.02067,113.75179&key=U6QBZ-ROQ3W-PFMRZ-O4VA5-LZOKQ-G7FZA&get_poi=1', success: res => { console.log(res); }, fail: err => console.log(err) })
或
wx.request({ url: 'https://apis.map.qq.com/ws/geocoder/v1/', data: { location: '23.02067,113.75179', key: 'U6QBZ-ROQ3W-PFMRZ-O4VA5-LZOKQ-G7FZA', get_poi: 1 }, success: res => { console.log(res); }, fail: err => console.log(err) })
qqmapsdk.search({ keyword: '酒店', success: (res) => { console.log(res); }, fail: (err) => { console.log(err); }, complete: () => { console.log('search done'); } });
wx.request({ url: 'https://apis.map.qq.com/ws/place/v1/search', data: { keyword: '酒店', key: 'U6QBZ-ROQ3W-PFMRZ-O4VA5-LZOKQ-G7FZA', boundary: 'nearby(23.02067,113.75179,1000,1)' }, success: res => { console.log(res); }, fail: err => console.log(err), complete: () => console.log('search done') })