|
@@ -5,9 +5,13 @@ Component({ |
|
@@ -5,9 +5,13 @@ Component({ |
|
5
|
* 组件的属性列表
|
5
|
* 组件的属性列表
|
|
6
|
*/
|
6
|
*/
|
|
7
|
properties: {
|
7
|
properties: {
|
|
8
|
- hasAllowFail:{
|
8
|
+ hasAllowFail:{//强制获取定位
|
|
9
|
type:Boolean,
|
9
|
type:Boolean,
|
|
10
|
value:false,
|
10
|
value:false,
|
|
|
|
11
|
+ },
|
|
|
|
12
|
+ hasAllowaAuthDeny:{//是否允许用户拒绝
|
|
|
|
13
|
+ type:Boolean,
|
|
|
|
14
|
+ value:true,
|
|
11
|
}
|
15
|
}
|
|
12
|
},
|
16
|
},
|
|
13
|
|
17
|
|
|
@@ -22,7 +26,7 @@ Component({ |
|
@@ -22,7 +26,7 @@ Component({ |
|
22
|
* 组件的方法列表
|
26
|
* 组件的方法列表
|
|
23
|
*/
|
27
|
*/
|
|
24
|
methods: {
|
28
|
methods: {
|
|
25
|
- getPos(){
|
29
|
+ getPos(fouce=false){
|
|
26
|
this._getPos().then(res => {
|
30
|
this._getPos().then(res => {
|
|
27
|
console.log('wx.getLocation.then', res);
|
31
|
console.log('wx.getLocation.then', res);
|
|
28
|
failCount=0;
|
32
|
failCount=0;
|
|
@@ -45,8 +49,10 @@ Component({ |
|
@@ -45,8 +49,10 @@ Component({ |
|
45
|
success:()=>{
|
49
|
success:()=>{
|
|
46
|
console.log('wx.showModal::success,给默认坐标');
|
50
|
console.log('wx.showModal::success,给默认坐标');
|
|
47
|
this.triggerEvent("pos",{
|
51
|
this.triggerEvent("pos",{
|
|
48
|
- latitude: 39.6846701,
|
|
|
|
49
|
- longitude: 118.1763001,
|
52
|
+ //latitude: 39.6846701,
|
|
|
|
53
|
+ //longitude: 118.1763001,
|
|
|
|
54
|
+ latitude:'',
|
|
|
|
55
|
+ longitude:'',
|
|
50
|
});
|
56
|
});
|
|
51
|
},
|
57
|
},
|
|
52
|
})
|
58
|
})
|
|
@@ -55,11 +61,18 @@ Component({ |
|
@@ -55,11 +61,18 @@ Component({ |
|
55
|
if ('getLocation:fail auth deny' == e.errMsg
|
61
|
if ('getLocation:fail auth deny' == e.errMsg
|
|
56
|
|| 'getLocation:fail:auth denied' == e.errMsg
|
62
|
|| 'getLocation:fail:auth denied' == e.errMsg
|
|
57
|
|| 'getLocation:fail authorize no response' == e.errMsg) {
|
63
|
|| 'getLocation:fail authorize no response' == e.errMsg) {
|
|
|
|
64
|
+ failCount=0;
|
|
|
|
65
|
+ if(this.data.hasAllowaAuthDeny && !fouce){
|
|
|
|
66
|
+ this.triggerEvent("pos",{
|
|
|
|
67
|
+ latitude: '',
|
|
|
|
68
|
+ longitude: '',
|
|
|
|
69
|
+ });
|
|
|
|
70
|
+ return;
|
|
|
|
71
|
+ }
|
|
58
|
this.selectComponent('#showModal').options({
|
72
|
this.selectComponent('#showModal').options({
|
|
59
|
header: '定位失败',
|
73
|
header: '定位失败',
|
|
60
|
body: '需要地理位置授权'
|
74
|
body: '需要地理位置授权'
|
|
61
|
}).show();
|
75
|
}).show();
|
|
62
|
- failCount=0;
|
|
|
|
63
|
} else {
|
76
|
} else {
|
|
64
|
failCount=failCount+1;
|
77
|
failCount=failCount+1;
|
|
65
|
setTimeout(() => {
|
78
|
setTimeout(() => {
|
|
@@ -71,9 +84,14 @@ Component({ |
|
@@ -71,9 +84,14 @@ Component({ |
|
71
|
_getPos(){
|
84
|
_getPos(){
|
|
72
|
return new Promise((success, fail) => {
|
85
|
return new Promise((success, fail) => {
|
|
73
|
let rex={latitude:'',longitude:''};
|
86
|
let rex={latitude:'',longitude:''};
|
|
|
|
87
|
+ wx.showLoading({
|
|
|
|
88
|
+ title: '包间查找中',
|
|
|
|
89
|
+ })
|
|
|
|
90
|
+ let hasSuccess=false;
|
|
74
|
wx.getLocation({
|
91
|
wx.getLocation({
|
|
75
|
type: 'gcj02',
|
92
|
type: 'gcj02',
|
|
76
|
success: (res) => {
|
93
|
success: (res) => {
|
|
|
|
94
|
+ hasSuccess=true;
|
|
77
|
rex=res;
|
95
|
rex=res;
|
|
78
|
success(res)
|
96
|
success(res)
|
|
79
|
},
|
97
|
},
|
|
@@ -81,11 +99,15 @@ Component({ |
|
@@ -81,11 +99,15 @@ Component({ |
|
81
|
fail(res)
|
99
|
fail(res)
|
|
82
|
},
|
100
|
},
|
|
83
|
complete: (res) => {
|
101
|
complete: (res) => {
|
|
|
|
102
|
+ wx.hideLoading()
|
|
84
|
console.log('wx.getLocation', res)
|
103
|
console.log('wx.getLocation', res)
|
|
85
|
}
|
104
|
}
|
|
86
|
});
|
105
|
});
|
|
87
|
setTimeout(()=>{
|
106
|
setTimeout(()=>{
|
|
88
|
- success(rex)
|
107
|
+ if(!hasSuccess){
|
|
|
|
108
|
+ success(rex)
|
|
|
|
109
|
+ wx.hideLoading()
|
|
|
|
110
|
+ }
|
|
89
|
},2000)
|
111
|
},2000)
|
|
90
|
})
|
112
|
})
|
|
91
|
},
|
113
|
},
|