How to set geolocation permissions for android?

I’m using the plugin org.apache.cordova.geolocation

This works fine on ios, but for Android it’s not firing. Am I correct that I need to set permissions like stated here: http://cordova.apache.org/docs/en/2.5.0/cordova_geolocation_geolocation.md.html

They mention:

app/res/xml/config.xml

<plugin name="Geolocation" value="org.apache.cordova.GeoBroker" />

app/AndroidManifest.xml

<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" />

I was wondering if I need to edit the AndroidManifest.xml and config.xml manually in the build folder?

Can I also set these permission in my ionic folder in /config.xml?

I’m confused where I can or need to set these options. Thanks for helping out!

I’m asking this because I don’t put the platforms/android folders in version control (since they are changing on every build). On the other hand I’d like to put these permission settings under version control so that it works on another dev machine as well.

update: I have set the options in the files mentioned above, but geolocation is not firing on android. No idea what’s wrong. Can I check logs somehow on the device itself?

Just go into your project and type :

cordova plugin add org.apache.cordova.geolocation

and then you can use the geolocation, with ng-cordova for example http://ngcordova.com/docs/#Geolocation

PS : your doc is a bit old, you can use this one - https://github.com/apache/cordova-plugin-geolocation/blob/master/doc/index.md

Aha, so permissions aren’t needed at all?

Thanks a lot!

well, I don’t remember having anything else to do to make it work, but I could be wrong.

And just as you did, the platforms/* and plugins/* folders are in my gitignore file :wink:

2 Likes

Hi @jorre - did you get geolocation working on Android?

I recently migrated a project to beta 14 and whereas this worked fine before, it no longer works on Android for me (works fine in iOS). I also updated to Cordova CLI to version 4 and also both Cordova Android and Cordova iOS, so things could have changed in a number of places.

Did you get it working?

You should switch off and switch on your phone once. Crazy but works

Thanks. Yeah - it just went away after restarting phone.

Is there any workarounds without having to do this?

Several changes made to Cordova requires new permissions, including Cordova whitelist plugin, find more about it in another forum question:

And just as you did, the platforms/* and plugins/* folders are in my gitignore file wink

This worked! Thank you so much!
But beyond that, I had to include my plugin list in file “package.json

YES THIS WORKED!. You will be prompted for permissions when you launch the app.
I was able to easily use HTML5

https://www.w3schools.com/html/html5_geolocation.asp

For visual studio, I needed to add this for cordova (anyway)
https://marketplace.visualstudio.com/items?itemName=MadsKristensen.NPMTaskRunner

Then I added the location plugin doing this:

https://taco.visualstudio.com/en-us/docs/manage-plugins/#Adding

and it worked.

Thanks a lot!

I hope my post helps someone else using ionic or cordova in visual studio!

What worked for me was typing this into project folder (Requires cordova 5.0+ ):

cordova plugin add cordova-plugin-geolocation

instead of this:

cordova plugin add org.apache.cordova.geolocation

sir i got 1. message: “application does not have sufficient geolocation permissions.” error do you how to fix ?