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 15:11:20 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
850d64c9f60ccb607904372e9e5b9405d85658cc
850d64c9
1 parent
68d9b1f6
fix 判断当前经纬度是否在目标经纬度的范围内函数修改
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
25 deletions
src/utils/tools.js
src/utils/tools.js
View file @
850d64c
/*
* @Date: 2024-07-31 17:19:25
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-12-2
0 16:09:42
* @LastEditTime: 2024-12-2
5 15:09:33
* @FilePath: /data-table/src/utils/tools.js
* @Description: 文件描述
*/
...
...
@@ -197,31 +197,44 @@ const isInViewport = (el) => { // 判断元素是否在可视区域
* @param {number} radius - 半径(单位:米)
* @returns {boolean} 是否在范围内
*/
// const isWithinRadius = (currentLat, currentLng, targetLat, targetLng, radius) => {
// const EARTH_RADIUS = 6371000; // 地球半径(单位:米)
// // 将角度转换为弧度
// const toRadians = (degrees) => (degrees * Math.PI) / 180;
// // 当前点和目标点的纬度差和经度差
// const deltaLat = toRadians(targetLat - currentLat);
// const deltaLng = toRadians(targetLng - currentLng);
// // 转换为弧度
// const radCurrentLat = toRadians(currentLat);
// const radTargetLat = toRadians(targetLat);
// // Haversine 公式计算两点间的距离
// const a =
// Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) +
// Math.cos(radCurrentLat) *
// Math.cos(radTargetLat) *
// Math.sin(deltaLng / 2) *
// Math.sin(deltaLng / 2);
// const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
// const distance = EARTH_RADIUS * c;
// // 判断距离是否在范围内
// return distance <= radius;
// }
const
isWithinRadius
=
(
currentLat
,
currentLng
,
targetLat
,
targetLng
,
radius
)
=>
{
const
EARTH_RADIUS
=
6371000
;
// 地球半径(单位:米)
// 将角度转换为弧度
const
toRadians
=
(
degrees
)
=>
(
degrees
*
Math
.
PI
)
/
180
;
// 当前点和目标点的纬度差和经度差
const
deltaLat
=
toRadians
(
targetLat
-
currentLat
);
const
deltaLng
=
toRadians
(
targetLng
-
currentLng
);
// 转换为弧度
const
radCurrentLat
=
toRadians
(
currentLat
);
const
radTargetLat
=
toRadians
(
targetLat
);
// Haversine 公式计算两点间的距离
const
a
=
Math
.
sin
(
deltaLat
/
2
)
*
Math
.
sin
(
deltaLat
/
2
)
+
Math
.
cos
(
radCurrentLat
)
*
Math
.
cos
(
radTargetLat
)
*
Math
.
sin
(
deltaLng
/
2
)
*
Math
.
sin
(
deltaLng
/
2
);
const
c
=
2
*
Math
.
atan2
(
Math
.
sqrt
(
a
),
Math
.
sqrt
(
1
-
a
));
const
distance
=
EARTH_RADIUS
*
c
;
// 判断距离是否在范围内
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
;
return
distance
<=
radius
;
}
...
...
Please
register
or
login
to post a comment