2***@qq.com
2***@qq.com
  • 发布:2023-04-21 09:10
  • 更新:2024-01-18 14:37
  • 阅读:469

【报Bug】每隔10秒,使用uni.getLocation获取手机位置,获取到的坐标来回跳动,分叉很多

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: windows10 22H2

HBuilderX类型: 正式

HBuilderX版本号: 3.7.9

手机系统: Android

手机系统版本号: Android 11

手机厂商: realme

手机机型: realme X2

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
setInterval(() => {   
        uni.getLocation({  
          type: "gcj02",  
          isHighAccuracy: true,  
          success: (res) => {  
            let longitude = res.longitude;  
            let latitude = res.latitude;  
            //polyline  
            this.polyline[0].points.push({ longitude, latitude });  
            //center  
            this.longitude = longitude;  
            this.latitude = latitude;  
            //marker  
            this.covers[0].longitude = longitude;  
            this.covers[0].latitude = latitude;  

            this.polyline = [...this.polyline];  
            this.covers = [...this.covers];  
          },  
          fail: (res) => {}  
        });  
      }, 10000);

操作步骤:
<map id="map" style="width: 100%; height: 300px;margin: 10rpx 0;" :latitude="latitude"  :longitude="longitude" :markers="covers" :polyline='polyline' />
setInterval(() => {   
        uni.getLocation({  
          type: "gcj02",  
          isHighAccuracy: true,  
          success: (res) => {  
            let longitude = res.longitude;  
            let latitude = res.latitude;  
            //polyline  
            this.polyline[0].points.push({ longitude, latitude });  
            //center  
            this.longitude = longitude;  
            this.latitude = latitude;  
            //marker  
            this.covers[0].longitude = longitude;  
            this.covers[0].latitude = latitude;  

            this.polyline = [...this.polyline];  
            this.covers = [...this.covers];  
          },  
          fail: (res) => {}  
        });  
      }, 10000);

预期结果:

一条比较正常的轨迹

实际结果:

轨迹飘忽不定,很多分叉,来回移动

bug描述:

发布的是app,每隔10秒,使用uni.getLocation获取手机位置,然后在map地图上绘制轨迹,结果绘制出来的轨迹经常出现偏移,明明是一条直线轨迹,结果取到的点位来回跳动,出现分叉。已经申请了高德安卓平台的key和证书。坐标系采用的是gcj02。PS:有没有别的解决方案呢?

2023-04-21 09:10 负责人:无 分享
已邀请:
刨地瓜

刨地瓜

timeout参数的值设置大一点,获取的位置会精确点。

2***@qq.com

2***@qq.com (作者)

就是不精确,也不该出现这么多分叉,这绘制的轨迹简直没法看呢

2***@qq.com

2***@qq.com (作者)

我试试把timeout设为8秒,看一下效果

  • 刨地瓜

    可以先设置得大一点,15秒这样。之前我这测试一般好像9秒左右才能出个高精度的位置

    2023-04-21 13:19

2***@qq.com

2***@qq.com (作者)

15秒的时间偏长了,如果有合适的替换方案也行啊,感觉和高德定位sdk有关系,但是证书和key都申请了,取坐标的时候,也没提示有啥问题

2***@qq.com

2***@qq.com (作者)

有没有专家解答一下啊,10秒的采集频率按说不高啊

2***@qq.com

2***@qq.com (作者)

专家大佬帮忙一下呢

y_j_x

y_j_x

我也遇到这个问题,我是切换后台或者息屏 每个2秒获取一下位置,然后连成一条线路,会发现有的点飘到三公里的地方,画出来怪怪的。客户还要处理掉飘点,我说是定位点的问题,他们可不管,

2***@qq.com

2***@qq.com

最后解决了吗

要回复问题请先登录注册