|
|
|
// components/userinfo/getpos.js
|
|
|
|
let failCount=0;
|
|
|
|
Component({
|
|
|
|
/**
|
|
|
|
* 组件的属性列表
|
|
|
|
*/
|
|
|
|
properties: {},
|
|
|
|
properties: {
|
|
|
|
hasAllowFail:{
|
|
|
|
type:Boolean,
|
|
|
|
value:false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 组件的初始数据
|
|
...
|
...
|
@@ -19,10 +25,19 @@ Component({ |
|
|
|
getPos(){
|
|
|
|
this._getPos().then(res => {
|
|
|
|
console.log('wx.getLocation.then', res);
|
|
|
|
failCount=0;
|
|
|
|
this.triggerEvent("pos",res);
|
|
|
|
}).catch((e) => {
|
|
|
|
console.log('wx.getLocation.catch', e);
|
|
|
|
if(e.errCode==2){//定位失败
|
|
|
|
console.log('wx.getLocation.catch', failCount,e);
|
|
|
|
if(this.data.hasAllowFail){
|
|
|
|
this.triggerEvent("pos",{
|
|
|
|
latitude: '',
|
|
|
|
longitude: '',
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(failCount>2){//定位失败
|
|
|
|
failCount=0;
|
|
|
|
wx.showModal({
|
|
|
|
title:'定位失败',
|
|
|
|
content:'请开启位置服务',
|
|
...
|
...
|
@@ -44,12 +59,13 @@ Component({ |
|
|
|
header: '定位失败',
|
|
|
|
body: '需要地理位置授权'
|
|
|
|
}).show();
|
|
|
|
failCount=0;
|
|
|
|
} else {
|
|
|
|
failCount=failCount+1;
|
|
|
|
setTimeout(() => {
|
|
|
|
this.getPos()
|
|
|
|
}, 500)
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
},
|
|
|
|
_getPos(){
|
...
|
...
|
|