demo1.js
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//index.js
//获取应用实例
Page({
data: { location: {}
},
onLoad: function () {
var that = this
wx.getLocation({
type: 'wgs84',
success: function (res) {
that.setData({
location: {
longitude: res.longitude,
latitude: res.latitude
}
})
}
})
//判断是否获得了用户地理位置授权
wx.getSetting({
success: (res) => {
if (!res.authSetting['scope.userLocation'])
that.openConfirm()
}
})
},
openConfirm: function () {
wx.showModal({
content: '检测到您没打开美团外卖的定位权限,是否去设置打开?',
confirmText: "确认",
cancelText: "取消",
success: function (res) {
console.log(res);
//点击“确认”时打开设置页面
if (res.confirm) {
console.log('用户点击确认')
wx.openSetting({
success: (res) => { }
})
} else {
console.log('用户点击取消')
}
}
});
},
})