小程序采坑:wx.getLocation不起作用,如何解决?

您所在的位置:网站首页 为什么小程序获取不了定位 小程序采坑:wx.getLocation不起作用,如何解决?

小程序采坑:wx.getLocation不起作用,如何解决?

2024-05-29 17:46| 来源: 网络整理| 查看: 265

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

新增定位

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    才知道设置中哪里不知道设置了不允许该小程序使用定位功能;  

解决办法:

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

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

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



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3