是否有任何方法可以重新请求用户获取其位置的权限,或使用带javascript的geolocation API删除旧设置



我正在构建一个应用程序,我需要用户的位置来完成注册,但我该如何让他允许呢?我的意思是,弹出窗口说"系统想访问你的位置,你想允许吗?",如果他/她允许,那没关系,但如果他/她的否认,我想重新问他,说一些类似的话,你不能继续,除非你允许我们获取你的位置,然后重新问他。因为我知道你可以清理你的位置设置,比如chorme设置等等,但我有什么办法可以通过javascript做到这一点吗?

这是我的功能

function pegaPaisUser(){
navigator.geolocation.getCurrentPosition(addPaisToUser,localizacaoNegada);
}
function localizacaoNegada(erro){
pegaPaisUser();
console.log("HERE")
}[![my console][1]][1]

当使用下面的代码时,我看到第一次点击网站时,我会被要求获得定位服务的权限。如果我拒绝并重试,我会在铬条中得到一个小图标,但仅此而已。看起来你应该向用户说明如何选择它。或者说服他们第一次访问。

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

相关内容

最新更新