更新代码
This commit is contained in:
21
app/Helpers/Location.php
Normal file
21
app/Helpers/Location.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
class Location
|
||||
{
|
||||
|
||||
public static function juli($user_lat = 0, $user_lng = 0, $lat = 0, $lng = 0)
|
||||
{
|
||||
if ($user_lat == 0 || $user_lng == 0 || $lat == 0 || $lng == 0) {
|
||||
return ''; //用户定位失败
|
||||
}
|
||||
|
||||
$juli = ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($user_lat * PI() / 180 - $lat * PI() / 180) / 2), 2) + COS($user_lat * PI() / 180) * COS($lat * PI() / 180) * POW(SIN(($user_lng * PI() / 180 - $lng * PI() / 180) / 2), 2))) * 1000);
|
||||
if ($juli > 1000) {
|
||||
return round($juli / 1000, 1) . 'Km';
|
||||
} else {
|
||||
return $juli . 'M';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user