0

I building an application and I need the user's location to finish his registration, but how do I do to make him allow? I mean, the pop up pops up and say "The system wants to access you location, do want to allow ?", if he/she allows, that's fine, but if he/she denies, I want re ask him, saying something like, you can't continue unless you allow us to get your location, and then re asks him. Because I know you can clean your location settings going to chorme settings and etc, but is there any way I can do it through javascript?

This is my function

function pegaPaisUser(){

   navigator.geolocation.getCurrentPosition(addPaisToUser,localizacaoNegada);
}

function localizacaoNegada(erro){
    pegaPaisUser();
    console.log("HERE")
}[![my console][1]][1]
izaac mendes
  • 434
  • 1
  • 4
  • 9
  • 1
    You can't because that would be spamming the user and the system prevents it. You can however notify the user that: in order to use this application, location services have to be on. Always leave it up to the user to make choices. – Emiel Zuurbier May 06 '20 at 19:23
  • And asking them again if they want to choose has to be through user interaction. So only in `click` event handler, for example. – Emiel Zuurbier May 06 '20 at 19:28
  • 1
    yeah, I know, but I would like to let him know how to do that, you know? If you still want to use the system, please go to blah blah, but if it takes too much work, I would like to make it easier for him by just re popping up the box, I am building using cordova btw – izaac mendes May 06 '20 at 19:28
  • It won't be that much. Create a button that asks the user to click it if they want to use location services, and in there your can re-query the user for location services. – Emiel Zuurbier May 06 '20 at 19:29
  • 1
    I tried, but chrome saves his choices and even if re call the function, id does nothing – izaac mendes May 06 '20 at 19:33
  • Show us what you've tried. I bet we can help you with that. – Emiel Zuurbier May 06 '20 at 19:34
  • 1
    Does this answer your question? [ask for geolocation permission again if it was denied](https://stackoverflow.com/questions/20678707/ask-for-geolocation-permission-again-if-it-was-denied) – Emiel Zuurbier May 06 '20 at 19:40

1 Answers1

1

When using the code below I see that the first I click on the site I will get asked for permission for the location services. If I deny and try again, I will get a small icon in the chrome bar, but nothing more. Seem like you should give your user directions in how to choose it. Or otherwise persuade them in giving access the first time.

<div class="message">
  <p>This application needs the location services. Please click the button if you want to allow location services to be used.</p>
  <button class="js-retry-location">Allow Location services</button>
</div>
const retryButton = document.querySelector('.js-retry-location');
retryButton.addEventListener('click', event => {
   navigator.geolocation.getCurrentPosition({ coords }=> {
     console.log(coords);
   });
});
Emiel Zuurbier
  • 19,095
  • 3
  • 17
  • 32