我是靠谱客的博主 淡定胡萝卜,这篇文章主要介绍小程序采坑:wx.getLocation不起作用,如何解决?,现在分享给大家,希望可以做个参考。

今天写个获取小程序定位的功能,发现怎么调用工具和真机都不需要调用官网wx.getLocation接口
wxml:

 <button  catchtap="Position"  >新增定位</button>

js:
 

 Position(e) {
    wx.getLocation({
      type: 'wgs84',
      success(res) {
        latitude = res.latitude
        longitude = res.longitude
        const speed = res.speed
        const accuracy = res.accuracy
        console.log(speed, accuracy, latitude, longitude)
      }
   })
   
  },

上面是当时代码,没有打印.后面查看资料,打印下fail;
js:

wx.getLocation({
      type: 'wgs84',
      success(res) {
        latitude = res.latitude
        longitude = res.longitude
        const speed = res.speed
        const accuracy = res.accuracy
        console.log(speed, accuracy, latitude, longitude)
      },
      fail: function (errInfo) {
        console.info(errInfo)
      }
  })

打印结果: 

getLocation:fail auth deny    才知道设置中哪里不知道设置了不允许该小程序使用定位功能;
 

解决办法:


先点击小程序右上角 三个点  ,然后出现设置,点击设置,将"使用我的地理位置"功能打开即可.
操作如下图:

我的分享到这里,如果对你有帮忙,请给我点赞.收藏.

如果你感觉有收获,欢迎给我打赏 ———— 以激励我输出更多优质内容

最后

以上就是淡定胡萝卜最近收集整理的关于小程序采坑:wx.getLocation不起作用,如何解决?的全部内容,更多相关小程序采坑:wx.getLocation不起作用,如何解决内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部