Hi all. Part of the code is to use the latitude and longitude obtained from the device. The problem I have is that it stopped asking if it is allowed to get the location, so now it does not get the latitude and longitude.
let posicion: string | number;
const getLocation = async () => {
try {
const position = await Geolocation.getCurrentPosition();
posicion=position.coords.latitude +"/"+ position.coords.longitude
return posicion;
} catch (e) {
return 0;
}
}
Is there a statement like asking for permissions? I mean a way to force the location to be enabled by the user when it is not active?
The Geo Location plugin has a method for requesting and checking permissions. If the location is critical to your app, then you probably need to check every time the app opens or before performing the action that requires it as the user could originally accept but then within iOS/Android remove the permission and your app would have no idea that they did.
1 Like
Thanks but How I can check every time? Perhaps the problem is that the testing is done in the browser. While the query to enable the permission works, it doesn’t always do so.
What is the location being used for? Is it critical for the functionality of the app? If it is critical, then I would check when the app mounts. If permissions aren’t granted, then request permission or tell the user they need to enable location permissions in order continue. If the app is in the background (still mounted) and the user removes location permissions, you could either just use their location from when permissions were enabled, or you would have to constantly check before getting them.
I know with Push Notification permissions, you cannot request them multiple times. Once the user accepts or rejects, future requests just return the current status. From there, you have to tell the user to go into the app settings within iOS/Android and enable the permission. Not sure if this is how the Geo Location permissions work.
1 Like
you first use the checkPermission method then if its false you use the request permission.
1 Like
I need to send the location to the server so that location-specific data is returned based on it. Therefore, this information is of vital importance.
But how can i request permission again?
Thats the question because checkPermission is not a method of Geolocation. I can not find a check method to call every component mounting.
Are you using the Capacitor Geo Location plugin? It has a checkPermissions
method here.
As @Hills90210 said, you first check permission and if no permission, then request it using the method requestPermissions
.
it is there. scroll to API section.