|
...
|
...
|
@@ -5,9 +5,13 @@ Component({ |
|
|
|
* 组件的属性列表
|
|
|
|
*/
|
|
|
|
properties: {
|
|
|
|
hasAllowFail:{
|
|
|
|
hasAllowFail:{//强制获取定位
|
|
|
|
type:Boolean,
|
|
|
|
value:false,
|
|
|
|
},
|
|
|
|
hasAllowaAuthDeny:{//是否允许用户拒绝
|
|
|
|
type:Boolean,
|
|
|
|
value:true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
...
|
...
|
@@ -22,7 +26,7 @@ Component({ |
|
|
|
* 组件的方法列表
|
|
|
|
*/
|
|
|
|
methods: {
|
|
|
|
getPos(){
|
|
|
|
getPos(fouce=false){
|
|
|
|
this._getPos().then(res => {
|
|
|
|
console.log('wx.getLocation.then', res);
|
|
|
|
failCount=0;
|
|
...
|
...
|
@@ -45,8 +49,10 @@ Component({ |
|
|
|
success:()=>{
|
|
|
|
console.log('wx.showModal::success,给默认坐标');
|
|
|
|
this.triggerEvent("pos",{
|
|
|
|
latitude: 39.6846701,
|
|
|
|
longitude: 118.1763001,
|
|
|
|
//latitude: 39.6846701,
|
|
|
|
//longitude: 118.1763001,
|
|
|
|
latitude:'',
|
|
|
|
longitude:'',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
})
|
|
...
|
...
|
@@ -55,11 +61,18 @@ Component({ |
|
|
|
if ('getLocation:fail auth deny' == e.errMsg
|
|
|
|
|| 'getLocation:fail:auth denied' == e.errMsg
|
|
|
|
|| 'getLocation:fail authorize no response' == e.errMsg) {
|
|
|
|
failCount=0;
|
|
|
|
if(this.data.hasAllowaAuthDeny && !fouce){
|
|
|
|
this.triggerEvent("pos",{
|
|
|
|
latitude: '',
|
|
|
|
longitude: '',
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.selectComponent('#showModal').options({
|
|
|
|
header: '定位失败',
|
|
|
|
body: '需要地理位置授权'
|
|
|
|
}).show();
|
|
|
|
failCount=0;
|
|
|
|
} else {
|
|
|
|
failCount=failCount+1;
|
|
|
|
setTimeout(() => {
|
|
...
|
...
|
@@ -71,9 +84,14 @@ Component({ |
|
|
|
_getPos(){
|
|
|
|
return new Promise((success, fail) => {
|
|
|
|
let rex={latitude:'',longitude:''};
|
|
|
|
wx.showLoading({
|
|
|
|
title: '包间查找中',
|
|
|
|
})
|
|
|
|
let hasSuccess=false;
|
|
|
|
wx.getLocation({
|
|
|
|
type: 'gcj02',
|
|
|
|
success: (res) => {
|
|
|
|
hasSuccess=true;
|
|
|
|
rex=res;
|
|
|
|
success(res)
|
|
|
|
},
|
|
...
|
...
|
@@ -81,11 +99,15 @@ Component({ |
|
|
|
fail(res)
|
|
|
|
},
|
|
|
|
complete: (res) => {
|
|
|
|
wx.hideLoading()
|
|
|
|
console.log('wx.getLocation', res)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setTimeout(()=>{
|
|
|
|
success(rex)
|
|
|
|
if(!hasSuccess){
|
|
|
|
success(rex)
|
|
|
|
wx.hideLoading()
|
|
|
|
}
|
|
|
|
},2000)
|
|
|
|
})
|
|
|
|
},
|
...
|
...
|
|