Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Permissions for geolocation access

$
0
0

@Bonsaiko wrote:

Hello,
I'm using geolocation in my app.
For some reason, when I launch the app, I'm not asked anything, and if geolocation access wasn't authorized, then the app doesn't work as it should.
So I was looking for how to have the app check the permission, and then ask for permission.
I installed the plugin called cordova-plugin-android-permissions

I followed the example and everythig was working fine.

Here's what I did:

		var permissions = cordova.plugins.permissions;
		var perm_to_check = permissions.CAMERA;
		// Vérification permission
		permissions.hasPermission(perm_to_check, callback);
		function callback(status) {
			if ( status.hasPermission ) {
			alert("Permission is set");
		  }
		  else {
			alert("Permission is not set");
			permissions.requestPermission(perm_to_check, success, error);
		  }
		}
		function error() {
		  console.warn('permission is not turned on');
		  alert('permission is not turned on');
		}
		function success( status ) {
		  if( !status.hasPermission ) error();
		  else alert('permission request accepted, permission turned on');
		}

When I run the app, it checks if the camera has permission. If it doen't, then I'm asked if I want to authirize or not. Until here everything's fine.

But in my case, I don't need camera, I need geolocation.

So I replaced this:

var perm_to_check = permissions.CAMERA;

by this:

var perm_to_check = permissions.ACCESS_FINE_LOCATION;

And what happens is: I have a message showing that I don't have permission, and that's it. I'm not asked for anything.

I even tried other values like ACCESS_COARSE_LOCATION, ACCESS_LOCATION_EXTRA_COMMANDS, ACCESS_MOCK_LOCATION - everything that contains the word location :slight_smile: but nothing worked.

What am i doing wrong ?
Can anyone help me with this please ?

Thanks a lot.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>