根据当前位置的经纬,查找最近的点

0 0 322

经纬度计算距离并排序。根据当前位置的经纬第  查找最近的点

select * from sb_user_geo order by ACOS(SIN((‘.$city_lat.’ * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((‘.$city_lat.’ * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS((‘.$city_lng.’ * 3.1415) / 180 – (lng * 3.1415) / 180 ) ) * 6380  asc  limit 30

PHP计算两点之间的距离:

/**
*求两个已知经纬度之间的距离,单位为千米
*@param lng1,lng2 经度
*@param lat1,lat2 纬度
*@return float 距离,单位千米
**/
private function _distance($lng1,$lat1,$lng2,$lat2)//根据经纬度计算距离
{
//将角度转为弧度
$radLat1=deg2rad($lat1);
$radLat2=deg2rad($lat2);
$radLng1=deg2rad($lng1);
$radLng2=deg2rad($lng2);
$a=$radLat1-$radLat2;//两纬度之差,纬度<90
$b=$radLng1-$radLng2;//两经度之差纬度<180
$s=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6378.137;

return $s;
}

留言

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>