请问一下wx.getLocation这个方法调用是否有频率限制?
发布于 7 年前 作者 aqiao 6231 次浏览 最后一次编辑是 6 年前 来自 官方Issues

请问一下wx.getLocation这个方法调用是否有频率限制。我在手机测试,打开了gps,然后在请求频率不高的情况下能够有返回值。但是请求频率较高后,一直无任何返回,不管是失败还是成功的返回都没有,感觉是方法调用被阻塞了。

2 回复

手机型号:红米note7 pro

微信版本号:Version 7.0.6

系统版本(安卓版本?):9

代码片段:

下面函数调用频率很高的时候,就阻塞了,且没有任何返回结果,微信小程序退到后台以后,隔了大概5分钟,小程序也没有被销毁,因为我在界面onshow方法里调用了这个方法,如果被销毁了,这个方法会重新被调用,但是并没有重新调用,或者可能是调用了没有返回结果。

https://developers.weixin.qq.com/s/9O2KPBm776ap

function getCurrentLocation(obj) {

    wx.getLocation({

      type: “gcj02”,

      success: function (res) {

        if(res.latitude != obj.data.latitude || res.longitude != obj.data.longitude){

          obj.setData({

            ‘longitude’: res.longitude,

            ‘latitude’: res.latitude

          });

          searchPoints(obj, points)

        }  

      },

      fail: function (res){

        console.log("Fail " + res);

        wx.hideLoading();

        wx.getSetting({

          success(settingRes) {

            if (!settingRes.authSetting[“scope.userLocation”]) {

              wx.showModal({

                title: ‘授权提示’,

                content: ‘需要获取您的地理位置,请确认授权,否则地图功能将无法使用!’,

                success: function (tip) {

                  if (tip.confirm){

                    wx.openSetting({

                      //点击确定则调其用户设置

                      success: function (data) {

                        if (data.authSetting[“scope.userLocation”] === true) {

                          //如果设置成功

                          wx.showToast({

                            //弹窗提示

                            title: “授权成功”,

                            icon: “success”,

                            duration: 1000

                          });

                          wx.showLoading({

                            title: ‘数据正在加载…’,

                          }),

                          wx.getLocation({ 

                            type: “gcj02”,

                            success: function (res) {

                                obj.setData({

                                  ‘longitude’: res.longitude,

                                  ‘latitude’: res.latitude

                                });

                                searchPoints(obj, points)

                              }

                           })

                         }

                       }

                    })

                  }

                }

              })

            }

          }

        })     

      },

      complete:function(){

        wx.vibrateLong();

      }

    })

 

}

麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

回到顶部