自己备注一下
1 /* 2 *参数说明: 3 *$lng 经度 4 *$lat 纬度 5 *$distance 周边半径 默认是500米(0.5Km) 6 */ 7 public function returnSquarePoint($lng, $lat,$distance = 0.5) { 8 $dlng = 2 * asin(sin($distance / (2 * 6371)) / cos(deg2rad($lat))); 9 $dlng = rad2deg($dlng); 10 $dlat = $distance/6371;//地球半径,平均半径为6371km 11 $dlat = rad2deg($dlat); 12 13 return array( 14 'left-top'=>array('lat'=>$lat + $dlat,'lng'=>$lng-$dlng), 15 'right-top'=>array('lat'=>$lat + $dlat, 'lng'=>$lng + $dlng), 16 'left-bottom'=>array('lat'=>$lat - $dlat, 'lng'=>$lng - $dlng), 17 'right-bottom'=>array('lat'=>$lat - $dlat, 'lng'=>$lng + $dlng) 18 ); 19 20 } 21 //附近的红包 22 //接收起点经纬度 $longitude, $latitude 23 public function Distance() { 24 $longitude=input('post.longitude'); 25 $latitude=input('post.latitude'); 26 $array = $this->returnSquarePoint($longitude, $latitude); 27 $map = array( 28 'latitude' => array(array('EGT',$array['right-bottom']['lat']),array('ELT',$array['left-top']['lat']),'and'), 29 'longitude' => array(array('EGT',$array['left-top']['lng']),array('ELT',$array['right-bottom']['lng']),'and'), 30 ); 31 $basic_equipment = db("hongbao"); 32 $data = $basic_equipment->where($map)->select(); 33 // echo $basic_equipment->getLastSql(); die(); //打印thinkPHP中对SQL语句 34 return SZXReturn($this->message[1],"1",$data); 35 }
怎么算出来的,可参考 https://www.jianshu.com/p/4903d86b4119