//计算范围,可以做搜索用户
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;
}
获取范围内的所有数据
$result = GetRange(110.325945,20.031541,5000);
$where = " (`jingdu` between ".$result['minLat']." and ".$result['maxLat'].") and ( `weidu` between ".$result['minLon']." and ".$result['maxLon']." ) ";
$query = $db->query("select * from ".DB_PRE."hospital where $where order BY id DESC ");
while ( $row = $db->fetch_array($query) ) {
$list[] = $row['all_name'];
}
print_r($list);