как ждать использования aprove на географическом местоположении, используя cordova LocationAccuracy - PullRequest
0 голосов
/ 06 июня 2018

Я использую LocationAccuracy на ionic, и у меня возникла проблема, когда приложение открыто без определения местоположения, приложение правильно запрашивает разрешение, но после этого он ничего не делает

, чтобы проверить, получило ли приложение разрешение

  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)
  }

я установил таймаут, чтобы проверить, куда идет код

1 Ответ

0 голосов
/ 06 июня 2018

Я решил эту проблему, перезагрузив страницу после выполнения запроса, я использовал window.location.reload ().не правильно, но сработало

...