企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
``` ##获取列表 public function get_distance_list(){ $EARTH = 6378.137; //地球半径 $PI = 3.1415926535898; //PI值 $lng = $this->lng; $lat = $this->lat; $res = Db::name('distributor') ->field("*,(2 * $EARTH* ASIN(SQRT(POW(SIN($PI*(" . $lat . "-lat)/360),2)+COS($PI*" . $lat . "/180)* COS(lat * $PI/180)*POW(SIN($PI*(" . $lng . "-lng)/360),2)))) as distance") ->order('distance asc') ->select(); if ($res) { foreach ($res as $k => $v) { $res[$k]['distance'] = $this->get_distance($lng, $lat, $v['lng'], $v['lat']); $res[$k]['image'] = $this->request->domain() . $v['image']; } } return code(200, '获取地图数据成功', $res); } ##获取单个 public function get_distance($lng1, $lat1, $lng2,$lat2) { // 将角度转为狐度 $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 * 1000; return number_format($s/1000,1); } ```