public function distance($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;
}
}
public function customerlist(){
$serviceid=$_POST['service_id'];
$lat=$_POST['lat'];
$lng=$_POST['lng'];
// $lat=39.73838; // 纬度
// $lng=116.339128; // 经度
if(empty($lat)||empty($lng)){
Error('定位失败',-2001);
}
// 三元桥 116.464052,39.967359
// 国贸 116.467524,39.914319
// $serviceid=367;
$where['o.serviceid']=$serviceid;
$where['u.type']='1';
// 找到这服务人员下所有的订单
$data =D('Order')->field('o.userid as clientid,sc.scorelevel as starts,u.photo as clientphoto,u.realname as clientname,u.lat,u.lng')->table('t_order as o')->join('t_order_evaluation_s_c as sc on sc.memberid=o.serviceid')->join('t_user as u on o.userid =u.id')->where($where)->group('u.id')->select();
// echo $m->getlastsql();
foreach ($data as $key => &$value) {
if($value['lng']&&$value['lat']){
$data[$key]['distance']=(string)round($this->distance($lat,$lng,$value['lat'],$value['lng'],"K"),2)."Km";
unset($data[$key]['lng']);
unset($data[$key]['lat']);
}else{
unset($data[$key]);
}
}
$count=COUNT($data);
Success(array('list'=>$data,'count'=>$count),1001);
}
如何根据地点知道经纬度。答案是百度拾取器。