PHP根据经纬度获取在范围坐标的数据
// 计算范围,可以做搜索用户
function GetRange($lat,$lon,$raidus){ //计算纬度 $degree = (24901 * 1609) / 360.0; $dpmLat = 1 / $degree; $radiusLat = $dpmLat * $raidus; $minLat = $lat - $radiusLat; //得到最小纬度 $maxLat = $lat + $radiusLat; //得到最大纬度 //计算经度 $mpdLng = $degree * cos($lat * (PI / 180)); $dpmLng = 1 / $mpdLng; $radiusLng = $dpmLng * $raidus; $minLng = $lon - $radiusLng; //得到最小经度 $maxLng = $lon + $radiusLng; //得到最大经度 //范围 $range = array( 'minLat' => $minLat, 'maxLat' => $maxLat, 'minLon' => $minLng, 'maxLon' => $maxLng ); return $range; }
// 获取范围内的所有数据
$where = " (`jingdu` between ".$result['minLat']." AND ".$result['maxLat'].") AND ( `weidu` between ".$result['minLon']." AND ".$result['maxLon']." ) "; $res = $db->query("SELECT * FROM ".DB_PRE."shops WHERE $where ORDER BY `id` DESC "); $list = array(); while ( $row = $db->fetch_array($res) ) { $list[] = $row['shops_name']; } print_r($list);
php资料