我必须根据乘客拉特和日志找到所有20公里的司机。
我有以下两张司机和乘客表。
passenger_id PASSENGER_NAME passenger_lat passenger_log
1 David 123.07 55.03
2 Sunil xyz.pq abc.7
和驱动程序表一样
Driver_id DRIVER_NAME Driver_lat Driver_log
1 Anil 123.07 55.03
2 Jamis 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
plz在php json和mysql中提供答案
答案 0 :(得分:1)
<?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);
}
答案 1 :(得分:0)
class distance
{
public function all_user()
{
$query="select * from driver_user";
$query_run= mysql_query($query);
// $row= mysql_fetch_assoc($query_run);
while($row= mysql_fetch_assoc($query_run))
{
$dis= $this->call_distance(10,20,$row['current_latitude'],$row['current_longitude']);
}
}
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);
}
}
$distance=new distance();
$distance->all_user();