Showing
2 changed files
with
18 additions
and
13 deletions
| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | * @Author: hookehuyr hookehuyr@gmail.com | 2 | * @Author: hookehuyr hookehuyr@gmail.com |
| 3 | * @Date: 2022-05-26 23:52:36 | 3 | * @Date: 2022-05-26 23:52:36 |
| 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 5 | - * @LastEditTime: 2024-12-25 14:49:43 | 5 | + * @LastEditTime: 2024-12-25 16:00:31 |
| 6 | * @FilePath: /data-table/src/App.vue | 6 | * @FilePath: /data-table/src/App.vue |
| 7 | * @Description: | 7 | * @Description: |
| 8 | --> | 8 | --> |
| ... | @@ -169,7 +169,7 @@ onMounted(async () => { | ... | @@ -169,7 +169,7 @@ onMounted(async () => { |
| 169 | const targetLng = form_setting.geofence_center_longitude; | 169 | const targetLng = form_setting.geofence_center_longitude; |
| 170 | const radius = form_setting.geofence_circle_radius; // 半径 1000 米 | 170 | const radius = form_setting.geofence_circle_radius; // 半径 1000 米 |
| 171 | wx.getLocation({ | 171 | wx.getLocation({ |
| 172 | - type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' | 172 | + type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' |
| 173 | success: function (res) { | 173 | success: function (res) { |
| 174 | let currentLat = res.latitude; // 纬度,浮点数,范围为90 ~ -90 | 174 | let currentLat = res.latitude; // 纬度,浮点数,范围为90 ~ -90 |
| 175 | let currentLng = res.longitude; // 经度,浮点数,范围为180 ~ -180。 | 175 | let currentLng = res.longitude; // 经度,浮点数,范围为180 ~ -180。 | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Date: 2024-07-31 17:19:25 | 2 | * @Date: 2024-07-31 17:19:25 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-12-25 15:09:33 | 4 | + * @LastEditTime: 2024-12-25 16:02:17 |
| 5 | * @FilePath: /data-table/src/utils/tools.js | 5 | * @FilePath: /data-table/src/utils/tools.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -225,16 +225,21 @@ const isInViewport = (el) => { // 判断元素是否在可视区域 | ... | @@ -225,16 +225,21 @@ const isInViewport = (el) => { // 判断元素是否在可视区域 |
| 225 | // return distance <= radius; | 225 | // return distance <= radius; |
| 226 | // } | 226 | // } |
| 227 | 227 | ||
| 228 | -const isWithinRadius = (currentLat, currentLng, targetLat, targetLng, radius) => { | 228 | +function calculateDistance(lat1, lng1, lat2, lng2) { |
| 229 | - const earthRadius = 6371; // 地球平均半径,单位为千米 | 229 | + var that = this; |
| 230 | - const toRadians = (angle) => angle * (Math.PI / 180); | 230 | + let rad1 = lat1 * Math.PI / 180.0; |
| 231 | - let dLat = toRadians(targetLat - currentLat); | 231 | + let rad2 = lat2 * Math.PI / 180.0; |
| 232 | - let dLng = toRadians(targetLng - currentLng); | 232 | + let a = rad1 - rad2; |
| 233 | - let a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + | 233 | + let b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0; |
| 234 | - Math.cos(toRadians(currentLat)) * Math.cos(toRadians(targetLat)) * | 234 | + let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) * Math.cos( |
| 235 | - Math.sin(dLng / 2) * Math.sin(dLng / 2); | 235 | + rad2) * Math.pow( |
| 236 | - let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | 236 | + Math.sin(b / 2), 2))); |
| 237 | - let distance = earthRadius * c; | 237 | + s = s * 6378137; // 地球半径改为米 |
| 238 | + s = Math.round(s); // 四舍五入取整,直接返回米 | ||
| 239 | + return s; // 返回距离,单位为米 | ||
| 240 | +} | ||
| 241 | +function isWithinRadius(currentLat, currentLng, targetLat, targetLng, radius) { | ||
| 242 | + const distance = calculateDistance(currentLat, currentLng, targetLat, targetLng); | ||
| 238 | return distance <= radius; | 243 | return distance <= radius; |
| 239 | } | 244 | } |
| 240 | 245 | ... | ... |
-
Please register or login to post a comment