如何等待使用cordova LocationAccurance进行地理位置验证?
我在Ionic上使用如何等待使用cordova LocationAccurance进行地理位置验证?,cordova,typescript,mobile,ionic3,cordova-plugins,Cordova,Typescript,Mobile,Ionic3,Cordova Plugins,我在Ionic上使用LocationAccuracy,当应用程序在未启用位置的情况下打开时出现问题,应用程序正确请求权限,但之后他什么也不做 代码以查看应用程序是否获得权限 autorizacoes(){ this.diagnostic.isLocationEnabled().then( (resp)=>{ if(resp){ this.on_load() }else{ this.diagnos
LocationAccuracy
,当应用程序在未启用位置的情况下打开时出现问题,应用程序正确请求权限,但之后他什么也不做
代码以查看应用程序是否获得权限
autorizacoes(){
this.diagnostic.isLocationEnabled().then(
(resp)=>{
if(resp){
this.on_load()
}else{
this.diagnostic.registerLocationStateChangeHandler(()=>{this.on_load()})
this.request_location()
}
}
).catch(err=>{
this.alertCtrl.create({
title: 'Erro',
buttons: [{ text: 'ok' }],
subTitle: 'Ative o gps para prosseguir'
}).present();
})
}
要请求的代码
request_location(){
this.carregando = true
this.locationAccuracy.canRequest().then((canRequest: boolean) => {
if (canRequest) {
this.status = 'pode pedir' this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(
() => {
this.status='vai esperar'
this.on_load()
},
).catch(err=>{
this.status = 'deu erro'
this.alertCtrl.create({
title: 'Erro',
buttons: [{ text: 'ok' }],
subTitle: 'Ative o gps para prosseguir'
}).present();
this.request_location()
})
}
else{
this.request_location()
}
});
}
最后,打开位置后要运行的代码
on_load() {
this.geolocation.getCurrentPosition().then((resp) => {
this.pegar_orcamentos_diponiveis(this.raio, { lat: resp.coords.latitude, lng: resp.coords.longitude });
console.log(this.orcamentos.length)
setTimeout(()=>{
//this dont run
this.autorizacoes()
},30000)
}).catch((error) => {
console.log('Error getting location', error);
this.autorizacoes()
});
setTimeout(() => {
this run
this.status = 'end of time'
this.autorizacoes()
}, 30000)
}
我放置了一个
超时
来测试代码的去向。我通过在发出请求后重新加载页面解决了这个问题,我使用了window.location.reload()。不是正确的方法,但有效我做了一些测试,问题出在getcurrentposition()中,它卡在那里了,有人知道为什么吗?