app.json "permission": { "scope.userLocation": { "desc": "你的位置信息将用于小程序位置接口的效果展示" } }
用到的页面 onShow: function () { var that = this; wx.getLocation({ type: 'gcj02', //返回可以用于wx.openLocation的经纬度 success: (res) => { console.log(res.longitude); console.log(res.latitude); that.setData({ longitude: res.longitude, latitude: res.latitude, }) } }); setTimeout(function(){that.getlist()},1000); }, getlist:function(){ var that = this; var url = App.globalData.URL + 'ymt/same_city'; App.wxRequest('POST',url,{ user_id:wx.getStorageSync('user_id'), //差一个定位参数 latitude:that.data.latitude, longitude: that.data.longitude, },(res)=>{ if(res.code == 200){ console.log(res.data) that.setData({ shoplist:res.data, }) }else { wx.showToast({ title: res.msg, icon: 'loading', duration: 1000 }) } }); },
//http://api.map.baidu.com/lbsapi/getpoint/ //$begin = $latitude.",".$longitude; public function find_distance($begin,$end){ $web_key = '63VBZ-GV334-GCOUM-XIU7S-4OOV2-RHF5T'; //企业号有IP限制 $test_key = 'TVFBZ-V3WWU-ZQNVH-2EDJZ-ZSIIH-NPBOD'; //测试KEY $url="https://apis.map.qq.com/ws/distance/v1/matrix?mode=driving&from=".$begin."&to=".$end."&key=".$test_key; $this->writeLog("距离",$url); $res = file_get_contents($url); $ar = json_decode($res,true); if(isset($ar['result']["rows"][0]["elements"][0]["distance"])){ return $ar['result']["rows"][0]["elements"][0]["distance"]; //单位:米 } return 0; }
浙公网安备 33010602011771号