getCityNameOFLocation: function() { var that = this; wx.getLocation({ type: ‘wgs84‘, // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 success: function(res){ console.log("定位成功"); var locationString = res.latitude + "," + res.longitude; //获取的经度纬度 wx.request({ url: ‘http://apis.map.qq.com/ws/geocoder/v1/?l&get_poi=1‘, //根据经纬度转换成具体地址 data: { "key" : "YLFBZ-WHAWI-ZXUGH-53Q65-TOJ7E-ADBNQ", "location" : locationString }, method: ‘GET‘, // header: {}, success: function(res){ // success console.log("请求成功"); console.log("请求数据:" + res.data.result.address); }, fail: function() { // fail console.log("请求失败"); }, complete: function() { // complete console.log("请求完成"); } }) }, fail: function() { // fail console.log("定位失败"); }, complete: function() { // complete console.log("定位完成"); } }) }
原文地址:https://www.cnblogs.com/gqx-html/p/8124975.html
时间: 2024-11-10 22:00:10