微信小程序獲取騰訊經緯度,得到具體地址
阿新 • • 發佈:2017-12-27
add 坐標 api res url 經緯度 git 轉換成 log
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("定位完成"); } }) }
微信小程序獲取騰訊經緯度,得到具體地址