php 腾讯 地图 api 计算 坐标 两点 距离 微信 网页 WebService API

        $r = https_request('http://apis.map.qq.com/ws/geocoder/v1/?address='.$addr['addr'].'&key=F2GBZ-SREWQ-A3K56-GSLK5-ELOHS-PRB2X');
        if($r['status'] == 0){
            $lng = $r['result']['location']['lng'];
            $lat = $r['result']['location']['lat'];
            
            $r2 = https_request("http://apis.map.qq.com/ws/distance/v1/?mode=driving&from=22.560060,113.868490&to=$lat,$lng&key=F2GBZ-SREWQ-A3K56-GSLK5-ELOHS-PRB2X");
            
            if($r2['status']==0){
                if($r2['result']['elements']['distance']>5000){
                    exit( json_encode(['check'=>0,'msg'=>'当前位置不在服务范围']) ); 
                }
            }else{
                exit( json_encode(['check'=>0,'msg'=>'计算距离出错']) ); 
            }
            
        }else{
            exit( json_encode(['check'=>0,'msg'=>'地理位置出错']) );
        }