javascript - Only block once for navigator.geolocation.getCurrentPoistion
问题描述
It seems the default behavior for:
navigator.geolocation.getCurrentPosition((position) => {
// doSomethingWithPoistion
})
makes it so if it's denied. It is denied for all subsequent calls. Is there a way so that when the user hits block on the popup, it's only for this immediate interaction?
That is to say I'm using location services on load of a page. I also have a button that prompts the same functionality. The button doesn't work if the user denies locations services(just get another error callback).
Is there a way to make it so on load denials are only for this callback and doesn't set it to continue to deny on subsequent getCurrentPosition
calls?
解决方案
从我在 Chrome 浏览器中重新制定时所知道的情况来看,与其说是拒绝地理定位调用,不如说是阻止了地理定位调用。
当运行您在 Chrome 中提供的代码片段时,只需通过点击按钮退出权限弹出窗口X
,我就可以在每次运行代码时触发权限提示。如果我点击Block
按钮关闭权限弹出窗口,该网站将添加到我在 Chrome 中被阻止的网站列表中,并且不再请求许可。
下面链接的这个解决方案似乎是处理这种情况的更好方法之一。它建议您检查地理定位权限的当前状态,并在当前被拒绝时通知用户。
推荐阅读
- ios - iPad上奇怪的UITextField(仅限)约束行为
- angular5 - 组件 ngOnInit 中的 Angular 订阅
- java - 如何在 Maven 项目之间进行聚合
- vim - Supertab:在特定单词后跟空格后自动完成
- laravel - 使用 Laravel 和 BackPack 的自定义逻辑
- ios - Core Data 自定义结构数组
- django - 如何在 django 中编译保存在数据库中的模板
- django - 通过 AWS Application Load Balancer 提供 Django 内容
- powershell - 如何将数组元素复制到 ReadOnlyCollection?
- java - 从 Firebase 存储到 Recycler 视图的图像