微信小程序结合腾讯地图定位当前城市(位置)

 onLoad(options) {
this.getUserLocation() },
/** * 定位地点 */ getUserLocation: function () { let _this = this wx.getLocation({ type: 'gcj02', // type有两中类型,gcj02 是腾讯地图所能解析的 success: res => { _this.setData({ locationObj: res }) // 调用获取城市名称方法 _this.getCity() } }) }, // 获取定位城市名称方法 getCity: function () { var _this = this wx.request({ url: `https://apis.map.qq.com/ws/geocoder/v1/?key=QDOBZ*********************VFQZ&location=`+ _this.data.locationObj.latitude + ',' +_this.data.locationObj.longitude, success: res => { console.log(res.data) // 此处返回的就是需要查询的城市名称 } }) }, })

 腾讯地图获取key

https://lbs.qq.com/dev/console/application/mine

posted @ 2022-04-21 19:53  王越666  阅读(566)  评论(0编辑  收藏  举报