web
2025-07-02 03bcdfbc9dd10e473686bbe27a8e615f5a22a283
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<template>
    <view class="device">
        <Navbar title="设备列表"></Navbar>
    </view>
</template>
 
<script setup>
    import{ ref, onMounted } from 'vue'
    import Navbar from '../../components/navbar/navbar.vue'
    
    const userLocation = ref()
    
    
    // 根据经纬度计算距离,根据经纬度计算距离,参数分别为第一点的纬度,经度(用户);第二点的纬度,经度(设备)
    const getDistances = (lat1, lon1, lat2, lon2) => {
        let EARTH_RADIUS = 6378.137;// 地球半径
        let radLat1 = lat1 * Math.PI / 180.0; //lat1 * Math.PI / 180.0=>弧度计算
        let radLat2 = lat2 * Math.PI / 180.0;
        let a = radLat1 - radLat2;
        let b = lon1 * Math.PI / 180.0 - lon2 * Math.PI / 180.0;
        let 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 * EARTH_RADIUS; 
        s = Math.round(s * 10000) / 10000;// 输出为公里
        return { m: s * 1000, km: Number(s.toFixed(2)) }
    }
    
    onMounted(() => {
        userLocation.value = JSON.parse(uni.getStorageSync('userLocation'))
    })
</script>
 
<style lang="scss" scoped>
</style>