Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
data-table
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2024-12-25 16:02:59 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
32677679cd9e58cb07aa1952b55e7c5c472158ef
32677679
1 parent
850d64c9
fix 完善定位精确度问题
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
13 deletions
src/App.vue
src/utils/tools.js
src/App.vue
View file @
3267767
...
...
@@ -2,7 +2,7 @@
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-26 23:52:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-12-25 1
4:49:43
* @LastEditTime: 2024-12-25 1
6:00:31
* @FilePath: /data-table/src/App.vue
* @Description:
-->
...
...
@@ -169,7 +169,7 @@ onMounted(async () => {
const targetLng = form_setting.geofence_center_longitude;
const radius = form_setting.geofence_circle_radius; // 半径 1000 米
wx.getLocation({
type: '
wgs84
', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
type: '
gcj02
', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
let currentLat = res.latitude; // 纬度,浮点数,范围为90 ~ -90
let currentLng = res.longitude; // 经度,浮点数,范围为180 ~ -180。
...
...
src/utils/tools.js
View file @
3267767
/*
* @Date: 2024-07-31 17:19:25
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-12-25 1
5:09:33
* @LastEditTime: 2024-12-25 1
6:02:17
* @FilePath: /data-table/src/utils/tools.js
* @Description: 文件描述
*/
...
...
@@ -225,16 +225,21 @@ const isInViewport = (el) => { // 判断元素是否在可视区域
// return distance <= radius;
// }
const
isWithinRadius
=
(
currentLat
,
currentLng
,
targetLat
,
targetLng
,
radius
)
=>
{
const
earthRadius
=
6371
;
// 地球平均半径,单位为千米
const
toRadians
=
(
angle
)
=>
angle
*
(
Math
.
PI
/
180
);
let
dLat
=
toRadians
(
targetLat
-
currentLat
);
let
dLng
=
toRadians
(
targetLng
-
currentLng
);
let
a
=
Math
.
sin
(
dLat
/
2
)
*
Math
.
sin
(
dLat
/
2
)
+
Math
.
cos
(
toRadians
(
currentLat
))
*
Math
.
cos
(
toRadians
(
targetLat
))
*
Math
.
sin
(
dLng
/
2
)
*
Math
.
sin
(
dLng
/
2
);
let
c
=
2
*
Math
.
atan2
(
Math
.
sqrt
(
a
),
Math
.
sqrt
(
1
-
a
));
let
distance
=
earthRadius
*
c
;
function
calculateDistance
(
lat1
,
lng1
,
lat2
,
lng2
)
{
var
that
=
this
;
let
rad1
=
lat1
*
Math
.
PI
/
180.0
;
let
rad2
=
lat2
*
Math
.
PI
/
180.0
;
let
a
=
rad1
-
rad2
;
let
b
=
lng1
*
Math
.
PI
/
180.0
-
lng2
*
Math
.
PI
/
180.0
;
let
s
=
2
*
Math
.
asin
(
Math
.
sqrt
(
Math
.
pow
(
Math
.
sin
(
a
/
2
),
2
)
+
Math
.
cos
(
rad1
)
*
Math
.
cos
(
rad2
)
*
Math
.
pow
(
Math
.
sin
(
b
/
2
),
2
)));
s
=
s
*
6378137
;
// 地球半径改为米
s
=
Math
.
round
(
s
);
// 四舍五入取整,直接返回米
return
s
;
// 返回距离,单位为米
}
function
isWithinRadius
(
currentLat
,
currentLng
,
targetLat
,
targetLng
,
radius
)
{
const
distance
=
calculateDistance
(
currentLat
,
currentLng
,
targetLat
,
targetLng
);
return
distance
<=
radius
;
}
...
...
Please
register
or
login
to post a comment