mysql php 数据库查询附近的好友

来源:互联网 发布:淘宝客推广佣金 编辑:程序博客网 时间:2024/04/28 20:47
$lon=$lon*3.1415926535898 / 180.0;
$lat=$lat*3.1415926535898 / 180.0;

// 根据经纬来计算附近的好友
$sql = "select * ,(ROUND( (2 * asin(sqrt(pow(sin(('".$lat."'-(lat*3.1415926535898 / 180.0))/2),2)+cos('".$lat."')*cos(lat*3.1415926535898 / 180.0)*pow(sin(('".$lon."'-lon*3.1415926535898 / 180.0)/2),2))))* 6378.137 *10000)/10)as distance from pt_user where u_id!='".$u_id."' order by distance asc limit 0,50";

其中 lon,lat 为数据库中的字段,   distance 的值单位为(米)。经过简单测试没有问题。   

原创粉丝点击