如果被拒绝,请再次询问地理位置许可

时间:2013-12-19 10:09:28

标签: javascript jquery cordova geolocation

我通过phonegap构建应用程序,并使用地理定位按钮。

如果用户第一次拒绝地理位置的许可,当他们再次点击地理定位按钮时,我又该如何申请许可?

目前我的代码结构是:

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')
}

3 个答案:

答案 0 :(得分:26)

你不能。

您唯一能做的就是在浏览器的设置中显示重新激活位置共享的说明(https://support.google.com/chrome/answer/142065?hl=en)。

答案 1 :(得分:4)

两种方法:

  1. 如果您使用的Chrome版本大于83.0.4103.97,请在网址中使用锁定图标

enter image description here

  1. 对于旧版的Chrome,下面的代码可以正常工作:

以下代码仅适用于Chrome。

步骤: 1.打开Chrome 2.打开控制台 3.在控制台中复制

   var allowGeoRecall = true

4。在控制台中复制功能

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. 在控制台中运行功能

    getLocation()

执行此操作后,系统将要求您允许分享您的职位。如果您的回答是否定的,则将再次询问您,直到您同意为止。

提示:如果用户的回答是否定的,请告诉他为什么需要坐标。对于他来说至关重要的是要了解这一步骤对于Web应用程序的良好运行至关重要。

答案 2 :(得分:2)

这可以在页面信息中重置,方法是单击URL旁边的锁定图标并允许“位置”来访问

相关问题