ask for geolocation permission again if it was denied

im building an app through phonegap, with a geolocation button.

if a user denies permission for geolocation the first time, how can i ask for permission again when they click the geolocation button again?

my code structure at the moment is:

function getLocation() {    
    if(navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition, positionError);

    } else {
        hideLoadingDiv()
        showError('Geolocation is not supported by this device')
    }
}

function positionError() {
    hideLoadingDiv()
    showError('Geolocation is not enabled. Please enable to use this feature')
}

Answers:

Answer

You can't.

The only thing you can do is to display the instructions to reactivate the location sharing in his browser's settings (https://support.google.com/chrome/answer/142065?hl=en).

Answer

This can be reset in Page Info which can be accessed by clicking the lock icon next to the URL and allowing Location

Answer

You can achieve this functionality, by checking the user's response and recalling the function again.

Steps: 1. Open Chrome 2. Open the console 3. Copy in the console

   var allowGeoRecall = true

4. Copy in the console the functions

function getLocation() {   
    console.log('getLocation was called') 
    if(navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition, positionError);
    } else {
        hideLoadingDiv()
        console.log('Geolocation is not supported by this device')
    }
}

function positionError() {    
    console.log('Geolocation is not enabled. Please enable to use this feature')

    if(allowGeoRecall) getLocation()
}

function showPosition(){
    console.log('posiiton accepted')
    allowGeoRecall = false
}
  1. Run the function in the console

    getLocation()

After running this you will be asked to allow to share your position. If your response is negative you will be asked again until you agree.

HINT: If your user ha a negative response, let him know why you need the coordinates. Is vital for him to understand that this step is vital for the good run of the web app.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.