wx.getLocation()位置不能及时更新
发布于 6 年前 作者 tcheng 2931 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

    本人拿着手机一直在移动,但是小程序中的经纬度却不能及时更新,几分钟还没有变化。

    我开发了一个类似功能安卓app,经纬度都能及时更新,且精度较高。

    本人去年完成这个功能的时候,测试效果还是不错,在楼顶移动时,精度可达3米。

  • 预期表现

    能及时更新位置信息,精度能与app一样,

  • 复现路径

可以直接在本人的小程序复现,我用的华为P10和P20手机都不能及时更新位置信息。

  • 提供一个最简复现 Demo

这是获取位置信息的方法

updateLocation: function() {
        var that = this;
        wx.getLocation({
            type: "wgs84",//gps定位
            altitude: true,
            success: function(res) {
                that.setData({
                    lat: res.latitude,
                    lon: res.longitude,
                    accuracy: res.accuracy,
                    speed: Math.round(res.speed * 3.6) > 0 ? Math.round(res.speed * 3.6) : 0
                })
                console.log(res.latitude+"--"+res.longitude+"--"+res.speed)
            },
            complete:function(res) {
                console.log(res)
            }
        });
    },

这是每秒更新一次位置信息的方法

openGPS: function(e) {
        isLocation = e.detail.value;
        if (isLocation) { //实时更新位置信息
            updateInterval = setInterval(this.updateLocation, 1000);
        } else {
            clearInterval(updateInterval);
            clearInterval(autoPlayInterval);
        }
    },
2 回复

你好,华为P10和P20的微信版本都是7.0.4么?请提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

老哥. 你在每秒钟调用一次 wx.getLocation 的时候. 会出现 卡顿的情况吗?

我在Android上测试. 会卡… 小米Mix2.

卡得我现在只能使用 高德的定位API了…

回到顶部