@perenyitamas wrote:
0
down vote
favorite
As you can see in the code below, first i am asking the user to turn on the location then i get the geolocation of the user. I should only go towards if the user accept or decline the location permission.THis way the answer is undefinied and i get to the “answer is no or undefinied” console log part. I need to wait for the answer, if i get the answer continue in the code.
async locationReq() { this.locationAccuracy.canRequest().then((canRequest: boolean) => { if (canRequest) { this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then( (success) => { if (success.message == this.locationAccuracy.SUCCESS_USER_AGREED || success.message==this.locationAccuracy.ERROR_USER_DISAGREED) { this.answer=true; } else{ this.answer=false; alert("Hiba történt. Kérlek próbáld újra!"); } }); } console.log(this.answer); }).then(() => { if (this.answer == true) { console.log("answer is true"); this.plt.ready().then(() => { let loader = this.loadingCtrl.create({ content: "Helyadatok lekérdezése..." }); loader.present(); var options = { timeout: 15000 }; this.geolocation.getCurrentPosition(options).then(resp => { this.lat = resp.coords.latitude; this.lang = resp.coords.longitude; loader.dismiss(); this.mapLoadingPresent(); }).catch(() => { this.lat = 47.49801; this.lang = 19.03991; loader.dismiss(); this.mapLoadingPresent(); this.presentToast(); }); }) } else { console.log("answer is no or undefinied"); } }); }
Posts: 1
Participants: 1