企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
首先,获得授权 ``` wx.getSetting({ success: res=> { if (!res.authSetting\['scope.userLocation'\]) { wx.authorize({//授权 scope: 'scope.userLocation', success() { this.locationData() //定位方法 } }) }else{ this.locationData()//定位方法 } } }) ``` 其次,获得当前位置的经纬度 ``` locationData: function(){ wx.getLocation({ type: 'wgs84', success: res=> { this.setData({ latitude: res.latitude, longitude: res.longitude }) } }) this.mapReverseGeo() } ``` 最后,解析经纬度获得地址名称 ``` mapReverseGeo() { var \_this = this; const latitude = \_this.data.latitude const longitude = \_this.data.longitude console.log(this.data.latitude) qqmapsdk.reverseGeocoder({ //位置坐标,默认获取当前位置,非必须参数 //Object格式 // location: { // latitude: \_this.data.latitude, // longitude: \_this.data.longitude // }, //String格式 location: latitude,longitude, success: function (res) {//成功后的回调 // console.log(res); // console.log(res.result.address\_component.city) _this.setData({ district:res.result.address\_component.district }) }, fail: function (error) { console.error(error); } }) } ```