gpt4 book ai didi

php - 如何通过经纬度查找20公里以内的用户

转载 作者:行者123 更新时间:2023-11-29 12:50:05 24 4
gpt4 key购买 nike

我必须根据乘客的纬度和日志找到 20 公里内的所有司机。

我有以下两张司机和乘客的表。
Passenger_id    passenger_name    passenger_lat    passenger_log
1                        大卫                       123.07                       55.03
2                        苏尼尔                       xyz.pq                        abc.7


和驱动程序表为


Driver_id      Driver_name              Driver_lat                   Driver_log
1                        阿尼尔                       123.07                       55.03
2                         贾米斯                       xyz.pq                        abc.7

现在我有passenger_lat和passenger_log的输入参数。基于此我必须返回20公里内的所有司机详细信息

 SELECT *, ( 6371 * acos( cos( radians({$lat}) ) * cos( radians( lat ) ) * cos( radians(   lng ) - radians({$lng}) ) + sin( radians({$lat}) ) * sin( radians( lat ) ) ) ) AS distance FROM positions HAVING distance <= {$radius} ORDER BY distance ASC 

请在 php json 和 mysql 中提供答案

最佳答案

<?php

class driver_service
{
public function find_driver($data)
{
$driver_details=array();
$driver_detail=array();
$query="select driver_user_id,first_name,last_name,phone_no,cpf_no,driver_email_id,driver_image,current_latitude,current_longitude from driver_user";
$query_run= mysql_query($query);
// $row= mysql_fetch_assoc($query_run);
while($row= mysql_fetch_assoc($query_run))
{
$driver=array();
$dis= $this->call_distance($data['user_latitude'],$data['user_longitude'],$row['current_latitude'],$row['current_longitude']);


if($dis<=50)
{
$driver['driver_details']=$row;
$driver_detail[]=$driver;

}
}

if(empty($driver_detail))
{
$driver_details['status']="2~there is no driver between 20 kms";

}
else{
$driver_details['status']="1~success";
$driver_details['details']=$driver_detail;
}
echo json_encode($driver_details);
}
public function call_distance($lat1, $lon1, $lat2, $lon2) {

$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;
return ($miles * 1.609344);
}


}
$driver_service=new driver_service();


if($_REQUEST['action'] == 'find_driver')
{
$driver_service->find_driver($_REQUEST);

}

关于php - 如何通过经纬度查找20公里以内的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24885250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com