dpa99c/cordova-plugin-request-location-accuracy

canRequest() is no longer working for me

Closed this issue · 2 comments

I haven't changed anything in my code but the canRequest function is always false for me now. No matter if i turn on or off the location on my phone (running it on android with ionic cordova run android) it is going to the console.log("failure") part all the time if i use the canRequest(). It was working without any problem some days ago (both location turned off or on).

async locationReq() {
    
    
    const canRequest = await this.locationAccuracy.canRequest();
    console.log(canRequest);
    if (canRequest) {
      
      const success = await this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then((success) => {
        
        if (success.code==1 || success.code==0){
          this.answer=true;
        }
        else{          
         alert("Hiba történt! Próbáld újra!")
        }
      });
    }
    else{
      console.log("failure");
    }

    if (this.answer == true) {
      console.log('answer is true');
      await this.plt.ready();

      const loader = this.loadingCtrl.create({
        content: 'Helyadatok lekérdezése...'
      });
      loader.present();

      const options = {
        timeout: 15000
      };

      try {
        const resp = await this.geolocation.getCurrentPosition(options);
        this.lat = resp.coords.latitude;
        this.lang = resp.coords.longitude;
      } catch (err) {
        this.lat = 47.49801;
        this.lang = 19.03991;
        this.presentToast(); // Not sure if this must be awaited..
      } finally {
        loader.dismiss();
        this.mapLoadingPresent();
      }
    } else {
      console.log('answer is no or undefinied');
    }

  }

Just re-tested canRequest() on Android 8.1 and it's still working fine - see below:

Please follow these steps to repeat my test and confirm this:

  • Clone and run the example project on an Android device:

git clone https://github.com/dpa99c/cordova-plugin-request-location-accuracy-example
cd cordova-plugin-request-location-accuracy-example
cordova platform add android@latest
cordova run android
  • Inspect the app's Cordova Webview using Chrome Developer Tools and execute the following in the console:

cordova.plugins.locationAccuracy.canRequest(function(can){console.log("Can request: "+!!can)},function(err){console.error(err)});

Here's the result from my test:
screenshot

A likely cause of your issue is that the appropriate <uses-permission> keys have been omitted from the AndroidManifest.xml - see here.

Thank you for your help, i am on vacation till Friday but just checked my config.xml and it is very weird because i don't have any permission part at all in it. Maybe some new plugin messed it ( i tried removing platform and adding them again before, but no result) and it was working some days ago. I found this in your config, i hope this is what i need:

 <platform name="android">
        <config-file parent="/*" target="AndroidManifest.xml">
            <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
            <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
            <uses-feature android:name="android.hardware.location.gps" />
        </config-file>
    </platform>