本文主要是介绍查询距离最近的查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//计算距离public function typeStoreList($type_id,$lat,$lng,$distance=10){$page=$this->request->param('page',1);$limit=$this->request->param('limit',10);$Map=new Map();$squares=$Map->getSquare($lat,$lng,$distance);//获取矩阵$where=[];$where[]=['status','=',1];$data['rows']=$this->field("*,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(({$lat}*PI()/180-lat*PI()/180)/2),2)+COS({$lat}*PI()/180)*COS(lat*PI()/180)*POW(SIN(($lng*PI()/180-lng*PI()/180)/2),2)))*1000) AS distan")->whereRaw("FIND_IN_SET($type_id,store_type_id)")->where($where)->where('lat','between',[$squares['left-bottom']['lat'],$squares['left-top']['lat']])->where('lng','between',[$squares['left-bottom']['lng'],$squares['right-bottom']['lng']])->order('distan','asc')->page($page,$limit)->select();foreach($data['rows'] as $k=>$v){$distance=$Map->getDistanceBetweenPointsNew($v['lat'], $v['lng'], $lat, $lng);$data['rows'][$k]['distance']=$distance;}$data['total']=$data['rows']->count();$res=['status'=>true,'msg'=>'success','data'=>$data];return $res;}
这篇关于查询距离最近的查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!