Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何等待使用cordova LocationAccurance进行地理位置验证?_Cordova_Typescript_Mobile_Ionic3_Cordova Plugins - Fatal编程技术网

如何等待使用cordova LocationAccurance进行地理位置验证?

如何等待使用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

我在Ionic上使用
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()中,它卡在那里了,有人知道为什么吗?