Commit 344760cf authored by zhuwei's avatar zhuwei

计算直线距离

parent abbf8f64
......@@ -3,6 +3,7 @@
namespace app\index\controller;
use app\index\extend\Basic;
use app\index\service\PositionService;
use app\index\service\UserCallStintService;
use app\model\GImageDepot;
......@@ -179,14 +180,19 @@ class ImageDepot extends Basic
public function ceshi()
{
$m = new UserCallStintService();
$user_id = 87;//135558 135562 87
// $res = $m->getUserBindList($user_id);
$res = $m->getUserReportAgentIdList($user_id);
dump($res);
$position_service = new PositionService();//121.168936,32.174486 121.187333,30.691674
$is_ = $position_service->checkDistance('32.174486', '121.168936', '30.691674', '121.187333', 500);
dump($is_);
$a = $position_service->getDistance('32.174486', '121.168936', '30.691674', '121.187333');
dump($a);
}
}
......@@ -54,7 +54,7 @@ class PositionService
$first_position = $a_latitude . ',' . $a_longitude;
$end_position = $b_latitude . ',' . $b_longitude;
$distance = $this->getPositionDistance($first_position, $end_position);
dump($distance);
if ($distance <= $limit_distance) {
$result = true;
} else {
......@@ -63,4 +63,26 @@ class PositionService
return $result;
}
/**
* 计算直线距离 举个栗子:('32.174486', '121.168936', '30.691674', '121.187333')
* @param $lat1
* @param $lng1
* @param $lat2
* @param $lng2
* @return int
*/
function getDistance($lat1, $lng1, $lat2, $lng2){
// 将角度转为狐度
$radLat1 = deg2rad($lat1);// deg2rad()函数将角度转换为弧度
$radLat2 = deg2rad($lat2);
$radLng1 = deg2rad($lng1);
$radLng2 = deg2rad($lng2);
$a = $radLat1 - $radLat2;
$b = $radLng1 - $radLng2;
$s = 2 * asin(sqrt(pow(sin($a / 2), 2)+cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137;
return $s;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment