php获取登录地点,使用Php获取最近的地点?

嗨在我的数据库中,我在这50个位置共有100个位置,离我最近的另外50个位置对我来说最长,所以我想使用此顺序对数据进行排序,因此我在这里计算距离

$latt=$_REQUEST['latt'];

$long=$_REQUEST['long'];

$start=$_REQUEST['start'];

function distancefind($lat1, $lon1, $lat2, $lon2, $unit) {

$theta = $lon1 - $lon2;

$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));

$dist = acos($dist);

$dist = rad2deg($dist);

$miles = $dist * 60 * 1.1515;

$unit = strtoupper($unit);

if ($unit == "K") {

return ($miles * 1.609344);

} else if ($unit == "N") {

return ($miles * 0.8684);

} else {

return $miles;

}

}

$c=0;

$limt=10;

if($start!=null)

{

$query="select * from tbl_MapDetails LIMIT $start,$limt";

}

$result=mysql_query($query);

if($result)

{

while($row=mysql_fetch_array($result))

{

$distance1=distancefind($latt,$long,$row['Latitude'],$row['Longitude'],"");

$message[$c]=array("ID"=>$row['LocationID'],"Address"=>$address,"City"=>$row['City']=($row['City'] != null)?$row['City']:"","State"=>$row['State']=($row['State'] !=null)?$row['State']:"","Country"=>$row['Country']=($row['Country']!=null)?$row['Country']:"","Zip"=>$row['Zip']=($row['Zip'] !=null)?$row['Zip']:"","Country"=>$row['Country']=($row['Country']!=null)?$row['Country']:"","Distance"=>$distance1=($distance1==null)?"0":$distance1,"Latitude"=>$row['Latitude']=($row['Latitude']!=null)?$row['Latitude']:"","Longitude"=>$row['Longitude']=($row['Longitude']!=null)?$row['Longitude']:"","Pic"=>$pic,"rating"=>$row1[0]=($row1[0]!=null)?$row1[0]:"","name"=>$row['LocationName']=($row['LocationName']!=null)?$row['LocationName']:"","note"=>$row['Note']=($row['Note']!=null)?$row['Note']:"","feature1"=>$row['FeatureIcon1']=($row['FeatureIcon1']!=null)?$row['FeatureIcon1']:"","feature2"=>$row['FeatureIcon2']=($row['FeatureIcon2']!=null)?$row['FeatureIcon2']:"","feature3"=>$row['FeatureIcon3']=($row['FeatureIcon3']!=null)?$row['FeatureIcon3']:"","selectLogo"=>$row['SelectIcon']=($row['SelectIcon']!=null)?$row['SelectIcon']:"");

$c++;

}所以我在这里每次得到10个位置,所以消息数组数据从最近到最远开始,我如何检查,请指导我

感谢您的提前

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值