经纬度范围获取
1 /**
2 * Desc: 根据经纬度,半径范围获取附近
3 * User: JamesLiu
4 * Date: 2019/5/13
5 * Time: 15:38
6 * @param $longitude 经度
7 * @param $latitude 纬度
8 * @param $raidus 半径范围(单位:米)
9 * @return array
10 */
11 public function getAround($longitude, $latitude, $raidus)
12 {
13 $PI = 3.14159265;
14 $degree = (24901 * 1609) / 360.0;
15 $dpmLat = 1 / $degree;
16 $radiusLat = $dpmLat * $raidus;
17 $minLat = $latitude - $radiusLat;
18 $maxLat = $latitude + $radiusLat;
19 $mpdLng = $degree * cos($latitude * ($PI / 180));
20 $dpmLng = 1 / $mpdLng;
21 $radiusLng = $dpmLng * $raidus;
22 $minLng = $longitude - $radiusLng;
23 $maxLng = $longitude + $radiusLng;
24 return array('minLng' => $minLng, 'maxLng' => $maxLng, 'minLat' => $minLat, 'maxLat' => $maxLat);
25 }
经纬度距离组装成sql
1 $array = $this->getAround(115.826646, 28.718022, 2000);
2 $condition['longitude'] = array(array('EGT', $array['minLng']), array('ELT', $array['maxLng']), 'and');//(`longitude` >= minLng) AND (`longitude` <= maxLng)
3 $condition['latitude'] = array(array('EGT', $array['minLat']), array('ELT', $array['maxLat']), 'and');//(`latitude` >= minLat) AND (`latitude` <=maxLat)