1 Reply Latest reply on Feb 9, 2018 5:17 PM by porterdude

    PhoneGap geolocation is not asking for permissions

    IsaacMellor Level 1

      Hi,

       

      I am trying to get the cordova-geolocation plugin to give me the current location using getCurrentPosition. However all I receive is the error message "Application does not have sufficient geolocation permissions".

       

      I am testing Android 7.0 Nougat.

       

      I have also tried using the Cordova-plugins-diagnostic plugin to ask for the permission runtime but this is not working either.

       

      This is my config.xml (minus sensitive stuff

       

      <access origin="*" />
      <access origin="*://*.googleapis.com/*" subdomains="true" />
      <access origin="*://*.gstatic.com/*" subdomains="true" />
      <access origin="*://*.google.com/*" subdomains="true" />
      <access origin="*://*.googleusercontent.com/*" subdomains="true" />

      <allow-intent href="http://*/*" />
      <allow-intent href="https://*/*" />
      <allow-intent href="tel:*" />
      <allow-intent href="sms:*" />
      <allow-intent href="mailto:*" />
      <allow-intent href="geo:*" />

      <platform name="android">
        <allow-intent href="market:*" />
      </platform>

      <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
      </platform>

      <preference name="Orientation" value="portrait" />
      <preference name="android-targetSdkVersion" value="27" />

      <plugin name="cordova-plugin-geolocation" spec="4.0.1" />
      <plugin name="cordova-plugin-whitelist" spec="1.3.3" />
      <plugin name="cordova-plugin-android-permissions" />
      <plugin name="cordova-custom-config" />
      <plugin name="cordova.plugins.diagnostic" />

      <platform name="android">
        <config-file target="AndroidManifest.xml" parent="/manifest">
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
        </config-file>
      </platform>

       

       

      And here is the code I am running to get the current location (The function is run on deviceready):

       

      function getPosition(){

        cordova.plugins.diagnostic.isLocationAuthorized(function(enabled){

         if(!enabled){

        cordova.plugins.diagnostic.requestLocationAuthorization(function(status){

       

         navigator.geolocation.getCurrentPosition(function(position){

         alert(position.coords.latitude, position.coords.longitude);
         startSplash();
         }, function(error){

         alert("Something went wrong while retrieving your position. " + error.message);
         },{

         maximumAge:6000,
         timeout:5000,
         enableHighAccuracy: true
         });

         },function(error){

         alert(error.message);
         });
         }

        },function(error){

         alert("The following error occurred: " + error.message);
         });
      }

       

      Any help would be greatly appreciated. I am absolutely stumped and have tried everything I can find everywhere else.

       

      Thanks

        • 1. Re: PhoneGap geolocation is not asking for permissions
          porterdude Level 1

          I had the same issue.  Tried numerous things others suggested and finally found something that worked.  I use the following plugin name in the config.xml file

           

          <plugin name="cordova-plugin-geolocation" version="2.1.0" />

           

          ...and I didn't use any of the android location permissions and for some reason it's working fine now.

           

          Hope that's helpful.

          5 people found this helpful