赞
踩
以上 8 个接口需完成准入开通流程
(1)普通开发者:需要在 “小程序管理后台 -「开发」-「开发管理」-「接口设置」” 中完成权限申请;
(2)第三方开发者:可通过 apply_privacy_interface 接口完成权限申请。
(1)在代码中使用的地理位置相关接口(共计 8 个,见表1),开发者均需要在 manifest.json 中 requiredPrivateInfos 配置项中声明,代码格式如下:
(2)表1中模糊位置信息(序号1)和精确位置信息(序号2-5)是互斥的,即声明了模糊位置信息就无法声明精确位置信息。若同时声明模糊位置信息和精确位置信息,则在编译代码时出现错误;
(3)注意:自 2022 年 7 月 14 日后发布的小程序,如果未在 app.json 中声明表1中的相关接口,则小程序调用这些接口(表1)时会出现错误,在 2022 年 7 月 14 日之前发布的小程序不受影响;
manifest.json中
"requiredPrivateInfos" : [ "chooseLocation"],
- uni.chooseLocation({
- success: function (res) {
- console.log('位置名称:' + res.name);
- console.log('详细地址:' + res.address);
- console.log('纬度:' + res.latitude);
- console.log('经度:' + res.longitude);
- }
- });
manifest.json中
- "permission": {
- "scope.userFuzzyLocation": {
- "desc": "你的位置信息将用于小程序位置接口的效果展示"
- }
- },
- "requiredPrivateInfos": [
- "getFuzzyLocation"
- ],
- uni.getSetting({
- success: (res) => {
- if (res.authSetting['scope.userFuzzyLocation']) {
- /* 用户授权时走这里 */
- this.getFuzzyLocationInfo()
- return
- }
- if (res.authSetting['scope.userFuzzyLocation'] === undefined) {
- /* 用户未授权时走这里 */
- uni.openSetting({
- success: (res) => {
- if (res.authSetting["scope.userFuzzyLocation"]) {
- this.getFuzzyLocationInfo()
- }
- }
- })
- } else {
- /* 用户拒绝了授权后走这里 */
- uni.openSetting({
- success: (res) => {
- if (res.authSetting["scope.userFuzzyLocation"]) {
- this.getFuzzyLocationInfo()
- }
- }
- })
- }
- },
- })

uni.openSetting:调起客户端小程序设置界面,返回用户设置的操作结果。
uni.getSetting:获取用户的当前设置。
authSetting:用户授权结果,其中 key 为 scope 值,value 为 Boolean 值,表示用户是否允许授权
- // 获取模糊地址
- getFuzzyLocationInfo() {
- wx.getFuzzyLocation({
- type: 'wgs84',
- success(res) {
- console.log('当前位置的经度:' + res.longitude);
- console.log('当前位置的纬度:' + res.latitude);
- }
- })
- },
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。