微信小程序开发 uni.getLocation定位不准确,解决方法

1,176 阅读1分钟

微信小程序开发时候使用uni.getLocation获取定位距离偏差几十公里 已经开启高精度 麻烦问下是什么问题 急

uni.getLocation({  
                type: 'gcj02',  
                isHighAccuracy: true,  
                success: (res) => {  
                    console.log(`${res.longitude},${res.latitude}`);  
                    resolve(`${res.longitude},${res.latitude}`)  
                },  
            })

您可以配合map组件,看一下定位的位置是否就是你当前的位置,如果地图的正中间有一个绿色的定位标识点,并且位置就是您所在的位置,那就说明拿到的经纬度没问题。

    <template>  
        <map :latitude="latitude" :longitude="longitude" style="width: 100vw; height: 100vh;" :show-location="true"></map>  
    </template>  
  
    <script>  
        export default {  
            data() {  
                return {  
                    latitude: '',  
                    longitude: ''  
                };  
            },  
            mounted() {  
                uni.getLocation({  
                    type: 'gcj02',  
                    isHighAccuracy: true,  
                    success: (res) => {  
                        console.log(res);  
                        this.latitude = res?.latitude;  
                        this.longitude = res.longitude;  
                    },  
                    fail(e) {  
                        console.log(e);  
                    }  
                })  
            },  
        };  
    </script>  
  
    <style>  
  
    </style>