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;
}

获取范围内的所有数据

$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);
联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2024

备案号:京ICP备15003423号-3