generated from liutk/owl-admin-base
切换坐标系
parent
67ab53ba94
commit
af9a9db29f
|
|
@ -15,6 +15,7 @@ use Illuminate\Http\Response;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Slowlyo\OwlAdmin\Services\AdminSettingService;
|
use Slowlyo\OwlAdmin\Services\AdminSettingService;
|
||||||
|
use coordtransform\Helper as CoordinateHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 考勤打卡
|
* 考勤打卡
|
||||||
|
|
@ -80,12 +81,11 @@ class SignController extends Controller
|
||||||
$lon = $request->input('lon');
|
$lon = $request->input('lon');
|
||||||
$lat = $request->input('lat');
|
$lat = $request->input('lat');
|
||||||
// 切换坐标系
|
// 切换坐标系
|
||||||
// $locationType = $request->input('location_type', 'wgs84');
|
$locationType = $request->input('location_type', 'wgs84');
|
||||||
// if ($locationType == 'wgs84') {
|
if ($locationType == 'wgs84') {
|
||||||
// $res = wgs84ToGcj02($lat, $lon);
|
list($lon, $lat) = CoordinateHelper::wgs84togcj02($lon, $lat);
|
||||||
// $lon = $res['lon'];
|
list($lon, $lat) = CoordinateHelper::gcj02tobd09($lon, $lat);
|
||||||
// $lat = $res['lat'];
|
}
|
||||||
// }
|
|
||||||
// 计算距离
|
// 计算距离
|
||||||
$distance = $service->haversineDistance(
|
$distance = $service->haversineDistance(
|
||||||
$lat,
|
$lat,
|
||||||
|
|
@ -142,12 +142,11 @@ class SignController extends Controller
|
||||||
$lon = $request->input('position.lon');
|
$lon = $request->input('position.lon');
|
||||||
$lat = $request->input('position.lat');
|
$lat = $request->input('position.lat');
|
||||||
// 切换坐标系
|
// 切换坐标系
|
||||||
// $locationType = $request->input('position.location_type', 'wgs84');
|
$locationType = $request->input('location_type', 'wgs84');
|
||||||
// if ($locationType == 'wgs84') {
|
if ($locationType == 'wgs84') {
|
||||||
// $res = wgs84ToGcj02($lat, $lon);
|
list($lon, $lat) = CoordinateHelper::wgs84togcj02($lon, $lat);
|
||||||
// $lon = $res['lon'];
|
list($lon, $lat) = CoordinateHelper::gcj02tobd09($lon, $lat);
|
||||||
// $lat = $res['lat'];
|
}
|
||||||
// }
|
|
||||||
$distance = $service->haversineDistance(
|
$distance = $service->haversineDistance(
|
||||||
$lat,
|
$lat,
|
||||||
$lon,
|
$lon,
|
||||||
|
|
|
||||||
|
|
@ -59,31 +59,3 @@ function delta($lat, $lon)
|
||||||
|
|
||||||
return ['lat' => $dLat, 'lon' => $dLon];
|
return ['lat' => $dLat, 'lon' => $dLon];
|
||||||
}
|
}
|
||||||
|
|
||||||
function wgs84ToGcj02($lat, $lon)
|
|
||||||
{
|
|
||||||
if (outOfChina($lat, $lon)) {
|
|
||||||
return ['lat' => $lat, 'lon' => $lon];
|
|
||||||
}
|
|
||||||
$d = delta($lat, $lon);
|
|
||||||
|
|
||||||
return ['lat' => $lat + $d['lat'], 'lon' => $lon + $d['lon']];
|
|
||||||
}
|
|
||||||
|
|
||||||
function gcj02ToWgs84($lat, $lon)
|
|
||||||
{
|
|
||||||
if (outOfChina($lat, $lon)) {
|
|
||||||
return ['lat' => $lat, 'lon' => $lon];
|
|
||||||
}
|
|
||||||
$d = delta($lat, $lon);
|
|
||||||
|
|
||||||
return ['lat' => $lat - $d['lat'], 'lon' => $lon - $d['lon']];
|
|
||||||
}
|
|
||||||
|
|
||||||
function outOfChina($lat, $lon)
|
|
||||||
{
|
|
||||||
return ($lon < 72.004 || $lon > 137.8347) || ($lat < 0.8293 || $lat > 55.8271);
|
|
||||||
}
|
|
||||||
// function pi() {
|
|
||||||
// return 3.14159265358979323846;
|
|
||||||
// }
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1",
|
"php": "^8.1",
|
||||||
"alphasnow/aliyun-oss-laravel": "^4.7",
|
"alphasnow/aliyun-oss-laravel": "^4.7",
|
||||||
|
"billy-poon/coordtransform": "^1.0",
|
||||||
"guzzlehttp/guzzle": "^7.2",
|
"guzzlehttp/guzzle": "^7.2",
|
||||||
"laravel/framework": "^10.10",
|
"laravel/framework": "^10.10",
|
||||||
"laravel/sanctum": "^3.3",
|
"laravel/sanctum": "^3.3",
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "e50204833e31b832f0bb8b3a5438e5ab",
|
"content-hash": "0d1bf59d3ee7e094a8d73020bc09799d",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "aliyuncs/oss-sdk-php",
|
"name": "aliyuncs/oss-sdk-php",
|
||||||
|
|
@ -141,6 +141,61 @@
|
||||||
],
|
],
|
||||||
"time": "2022-12-03T14:27:07+00:00"
|
"time": "2022-12-03T14:27:07+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "billy-poon/coordtransform",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/billy-poon/coordtransform.git",
|
||||||
|
"reference": "2f4454dae3a3515e33bbe3885490581f0ce29e6a"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/billy-poon/coordtransform/zipball/2f4454dae3a3515e33bbe3885490581f0ce29e6a",
|
||||||
|
"reference": "2f4454dae3a3515e33bbe3885490581f0ce29e6a",
|
||||||
|
"shasum": "",
|
||||||
|
"mirrors": [
|
||||||
|
{
|
||||||
|
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||||
|
"preferred": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.4"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"coordtransform\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Billy Poon",
|
||||||
|
"email": "panqbi@yeah.net",
|
||||||
|
"homepage": "https://github.com/billy-poon"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "一个提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换的工具模块。移植自:https://github.com/wandergis/coordtransform/",
|
||||||
|
"homepage": "https://github.com/billy-poon/coordtransform",
|
||||||
|
"keywords": [
|
||||||
|
"bd09",
|
||||||
|
"coordinate",
|
||||||
|
"gcj02",
|
||||||
|
"transform",
|
||||||
|
"wgs84"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/billy-poon/coordtransform/issues",
|
||||||
|
"source": "https://github.com/billy-poon/coordtransform/tree/master"
|
||||||
|
},
|
||||||
|
"time": "2018-08-21T17:33:38+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
"version": "0.11.0",
|
"version": "0.11.0",
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,13 @@
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
// use Illuminate\Foundation\Testing\RefreshDatabase;
|
// use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
|
use App\Admin\Services\EmployeeSignService;
|
||||||
|
use App\Admin\Services\StoreService;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
use coordtransform\Helper as CoordinateHelper;
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
class ExampleTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -12,6 +17,20 @@ class ExampleTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function test_the_application_returns_a_successful_response(): void
|
public function test_the_application_returns_a_successful_response(): void
|
||||||
{
|
{
|
||||||
dump(wgs84ToGcj02('29.421605', '106.524698'));
|
// GPS 坐标
|
||||||
|
$lon = '106.524698';
|
||||||
|
$lat = '29.421605';
|
||||||
|
|
||||||
|
// 百度接口转换结果
|
||||||
|
// $lon = '106.53499612144785';
|
||||||
|
// $lat = '29.424741925277104';
|
||||||
|
|
||||||
|
list($lon, $lat) = CoordinateHelper::wgs84togcj02($lon, $lat);
|
||||||
|
list($lon, $lat) = CoordinateHelper::gcj02tobd09($lon, $lat);
|
||||||
|
|
||||||
|
// BD-09 坐标
|
||||||
|
$lon2 = '106.534967';
|
||||||
|
$lat2 = '29.424352';
|
||||||
|
dump(EmployeeSignService::make()->haversineDistance($lat, $lon, $lat2, $lon2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue