微信小程序获取位置服务

复制代码
    wx.getLocation({
      type: 'gcj02',
      success(res) {
        wx.log('定位成功');
      },
      fail(err) {
        wx.log('定位失败', err);
        wx.showModal({
          content: '请打开手机和小程序中的定位服务',
          success: (modRes) => {
            if (modRes.confirm) {
              wx.openSetting({
                success(setRes) {
                  if (setRes.authSetting['scope.userLocation']) {
                    wx.log.log('定位打开成功...');
                  } else {
                    setTimeout(() => {
                      wx.showModal({
                        content: '请打开手机和小程序中的定位服务',
                        showCancel: false,
                        success: (res) => {
                          wx.log('定位成功');
                        }
                      })
                    }, 500);
                  }
                },
                fail(err) {
                  wx.log('定位失败');
                }
              })
            } else {
              wx.log('定位失败');
            }
          },
          fail: (err) => {
            wx.log('定位失败',err);
          }
        })
      }
    })

© 著作权归作者所有,转载或内容合作请联系作者

喜欢的朋友记得点赞、收藏、关注哦!!!

相关推荐
无心水4 小时前
【全域智能营销实战】2、Spring AI 模块化架构深度解读:从 1.0 到 2.0 的演进与最佳实践
人工智能·spring·架构·harness·顶尖架构师·全域智能营销·harmess
livemetee9 小时前
【关于Spring声明式事务】
java·后端·spring
czysoft9 小时前
se被限速
科技·学习·it·技术·魔法·先进·领先
小强库计算机毕业设计11 小时前
源码分享Spring Boot + Vue3 的校园社团管理系统
java·spring boot·后端·计算机毕业设计
Esaka_Forever11 小时前
Python 完整内存管理机制详解
开发语言·python·spring
格子软件11 小时前
2026年分布式GEO代理流量调度:源码级状态机防重挂实战
java·vue.js·人工智能·spring boot·分布式·vue
万亿少女的梦16811 小时前
基于Spring Boot的天空影院电影网站系统设计与实现
java·spring boot·mysql·vue·系统设计
万亿少女的梦16811 小时前
基于Spring Boot的社区管理系统设计与实现
java·spring boot·mysql·vue·系统设计
殳翰11 小时前
spring对junit的支持
spring·junit·sqlserver