App({
讯享网
讯享网</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">获取用户地理位置权限</span> getPermission:<span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)">(obj){ wx.chooseLocation({ success: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (res) { obj.setData({ addr: res.address </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">调用成功直接设置地址</span> })
}, fail:</span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)">(){ wx.getSetting({ success: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (res) { </span><span style="color: rgba(0, 0, 255, 1)">var</span> statu =<span style="color: rgba(0, 0, 0, 1)"> res.authSetting; </span><span style="color: rgba(0, 0, 255, 1)">if</span> (!statu['scope.userLocation'<span style="color: rgba(0, 0, 0, 1)">]) { wx.showModal({ title: </span>'是否授权当前位置'<span style="color: rgba(0, 0, 0, 1)">, content: </span>'需要获取您的地理位置,请确认授权,否则地图功能将无法使用'<span style="color: rgba(0, 0, 0, 1)">, success: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (tip) { </span><span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (tip.confirm) { wx.openSetting({ success: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (data) { </span><span style="color: rgba(0, 0, 255, 1)">if</span> (data.authSetting["scope.userLocation"] === <span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">) { wx.showToast({ title: </span>'授权成功'<span style="color: rgba(0, 0, 0, 1)">, icon: </span>'success'<span style="color: rgba(0, 0, 0, 1)">, duration: </span>1000<span style="color: rgba(0, 0, 0, 1)"> }) </span><span style="color: rgba(0, 128, 0, 1)">//授权</span><span style="color: rgba(0, 128, 0, 1)">成功之后,再调用chooseLocation选择地方</span> wx.chooseLocation({
讯享网 success: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)">(res) { obj.setData({ addr: res.address }) }, }) } </span><span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> { wx.showToast({ title: </span>'授权失败'<span style="color: rgba(0, 0, 0, 1)">, icon: </span>'success'<span style="color: rgba(0, 0, 0, 1)">, duration: </span>1000<span style="color: rgba(0, 0, 0, 1)"> }) } } }) } } }) } }, fail: </span><span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (res) { wx.showToast({ title: </span>'调用授权窗口失败'<span style="color: rgba(0, 0, 0, 1)">, icon: </span>'success'<span style="color: rgba(0, 0, 0, 1)">, duration: </span>1000<span style="color: rgba(0, 0, 0, 1)"> }) } }) } }) },
})

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/184914.html