From e129f41b200e2aeb623c1c5c77c76bd826c7bfbc Mon Sep 17 00:00:00 2001 From: XiaoXinPro 14 IAH5R <568170040@qq.com> Date: Fri, 17 Feb 2023 15:38:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E4=B8=8E=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/index.js | 39 +++++++++++++++++++++++++++ src/views/myPage/myPage.vue | 54 +++++++++++++++++-------------------- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index efe43a1..6fc1250 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -113,3 +113,42 @@ export function timestampToTime(timestamp, format) { export function getDeviceType() { return navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i) } + + + + +/** +* @description:根据经纬度计算距离 +* @param {*} locationInfo (lat1, lng1, lat2, lng2) +* @return: distanceObj: { distance , distance_str } +*/ +export function getDistances(lat1, lng1, lat2, lng2) { + + function rad(d) { + return d * Math.PI / 180.0; + } + var radLat1 = rad(lat1); + var radLat2 = rad(lat2); + var a = radLat1 - radLat2; + var b = rad(lng1) - rad(lng2); + var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); + s = s * 6378.137; + s = Math.round(s * 10000) / 10000; + + var distance = s; + var distance_str = ""; + + if (parseInt(distance) >= 1) { + distance_str = distance.toFixed(2) + "km"; + } else { + distance_str = (distance * 1000).toFixed(2) + "m"; + } + + let objData = { + distance: distance, + distance_str: distance_str + } + return objData +} + diff --git a/src/views/myPage/myPage.vue b/src/views/myPage/myPage.vue index 98628a0..41adec8 100644 --- a/src/views/myPage/myPage.vue +++ b/src/views/myPage/myPage.vue @@ -24,8 +24,12 @@