获取用户当前所在位置
1. 授权并获取经纬度
调用 wx.getLocation 来进行授权,使用此属性时应注意在App.json文件中进行配置
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
这是提示用户要干嘛的弹窗信息
wx.getSetting 判断用户是否已授权,
// 定位
position() {
wx.getSetting({
success: (res) => {
// res.authSetting['scope.userLocation'] == undefined 表示 初始化进入该页面
// res.authSetting['scope.userLocation'] == false 表示 非初始化进入该页面,且未授权
// res.authSetting['scope.userLocation'] == true 表示 地理位置授权
if (res.authSetting['scope.address.userLocation'] != undefined && res.authSetting['scope.address.userLocation'] != true) {
wx.showModal({
title: '请求授权当前位置',
content: '需要获取您的地理位置,请确认授权',
success: function (res) {
if (res.cancel) {
wx.showToast({
ti