uni-app:微信小程序:使用位置前先判断是否有权限授权(hbuilderx 3.7.3)
2023-09-14 08:59:32 时间
一,代码:
<template> <view> <button style="width:710rpx;height:80rpx;" @click="getSetting">打开地图</button> </view> </template> <script> export default { data() { return { } }, methods: { openMap(){ uni.getLocation({ success: res => { console.log('location success', res) uni.openLocation({ latitude: res.latitude, longitude: res.longitude, scale: 18 }) }, fail:res=>{ console.log('location fail', res) } }); }, //得到权限列表 getSetting(){ let that = this; uni.getSetting({ success: function(res) { var authList = res.authSetting; console.log(authList); if (!authList['scope.userLocation']) { console.log("未得到位置权限"); that.openSetting(); } else { console.log("已得到位置权限"); that.openMap(); } }, }); }, //打开一项权限 openSetting(){ let that = this; uni.showModal({ title: '是否授权当前位置', content: '需要获取您的地理位置,请确认授权,否则定位功能将无法使用', success(tip) { if (tip.confirm) { uni.authorize({ scope: 'scope.userLocation', success() { uni.showToast({ title: '授权成功', icon: 'success', duration: 1000 }); setTimeout(function() { that.openMap(); }, 1000) } }) } else { uni.showToast({ title: '授权失败', icon: 'none', duration: 1000 }) } }, }); }, } } </script> <style> </style>
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,测试效果
三,查看hbuilderx的版本:
相关文章
- 微信支付(公众号支付APIJS、app支付)服务端统一下单接口java版
- [Android Pro] app_process command in Android
- 【Python3网络爬虫开发实战】 1.7-App爬取相关库的安装
- uni-app:微信小程序:预加载字体文件(hbuilderx 3.7.3)
- uni-app+php:微信小程序登录:用code得到openid/unionid(hbuilderx 3.7.3)
- uni-app:微信小程序:使用外部字体(hbuilderx 3.7.3)
- js判断移动端是否安装某款app的多种方法
- [React] Create & Deploy a Universal React App using Zeit Next
- uni-app:微信小程序:得到用户的微信头像和昵称(hbuilderx 3.7.3)
- uni-app:微信小程序:使用位置权限getlocation时报错(hbuilderx 3.7.3)
- uni-app:微信小程序:使用外部字体(hbuilderx 3.7.3)
- 微信小程序----App生命周期
- [FAQ] uni-app 运行微信小程序 main.wxss 报错 unexpected token "$"
- paip.提高效率---微信 手机app快速开发平台—微网络撬动大市场
- html、vue、uni-app微信小程序的区别
- Android面试-Android性能优化和内存优化、APP启动速度一线大厂的实战案例解析
- android 11.0 安装低版本app 弹出应用版本过低警告窗
- Android 进入其他app和退出App杀死进程的方法详解
- 微信小程序:uni-app页面Page和组件Component生命周期执行的先后顺序
- IT周盘点 Android12发布,微信中止小程序跳转App,防挖矿英伟达限制显卡性能,乐视高调回归
- app自动化测试(Android)--App 控件定位
- 在微信开发者工具里运行微信小程序出现[ app.json 文件内容错误] (app.json: app.json 未找到)
- 微信小程序_uni-app_轮播图组件_swiper