Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
344760cf
Commit
344760cf
authored
Sep 18, 2019
by
zhuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
计算直线距离
parent
abbf8f64
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
ImageDepot.php
application/index/controller/ImageDepot.php
+11
-5
PositionService.php
application/index/service/PositionService.php
+24
-1
No files found.
application/index/controller/ImageDepot.php
View file @
344760cf
...
...
@@ -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
);
}
}
application/index/service/PositionService.php
View file @
344760cf
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment