js代码:
// 获取地理位置
wx.getLocation({ type: 'gcj02', success(res) { const latitude = res.latitude const longitude = res.longitude wx.request({ url: server + '/wechat/message/getlocation?lon=' + longitude + '&lat=' + latitude, success: function (res) { var da = res.data.result.formatted_address; that.setData({ HomeAddress: da }); } }) } })
后台PHP代码:
// 获取地址
public function getlocation(){ $get = input('get.'); $url = 'http://api.map.baidu.com/geocoder/v2/?ak=D6WOzHaymzVVKvgiy8UbhQEznkgeK6BD&location='.$get['lat'].','.$get['lon'].'&output=json'; $datas = $this->curlGet($url); echo $datas; }