uni-app使用uni.authorize检测是否授权获取地理位置

在如今社会中对于各类的权限越来越加严格,关于授权也变成了使用前必须的检测及操作。本篇文章就来介绍在开发中,如何关于授权的检测及操作。

uni-app开发使用uni.authorize来检测用户是否授权获取地理位置功能,具体代码如下:

uni.authorize({
scope: 'scope.userLocation',
success() {
//成功授权获取定位
uni.getLocation({
type: 'wgs84',
success: function (address) {
console.log('当前位置的经度:' + address.longitude);
console.log('当前位置的纬度:' + address.latitude);
}
})
},
fail(){
console.log("未授权获取定位信息")
}
})

uni.authorize中关于scope参数配置:

    scope.userInfo:用户信息

    scope.userLocation:地理位置

    scope.userLocationBackground:后台定位

    scope.address:通信地址

    scope.record:录音功能

    scope.writePhotosAlbum:保存到相册

    scope.camera:摄像头

    scope.invoice:获取发票

    scope.invoiceTitle:发票抬头

    scope.werun:微信运动步数

注意项:

    scope参数并不是所有小程序都适用,如werun仅支持微信小程序。所以在使用时,需要注意对应平台是否可用。


六月初字帖坊小程序 你想要的字帖模板及工具,这里都有!