用户在javascript中阻止访问后请求位置坐标 [英] Request location coordinates after user has blocked access in javascript

查看:54
本文介绍了用户在javascript中阻止访问后请求位置坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果他们过去阻止了我的请求,我该如何提示用户使用javascript进行地理位置定位? (使用 navigator.geolocation.getCurrentPosition ).

How can I prompt a user for their geo-location in javascript if they've blocked my request in the past? (using navigator.geolocation.getCurrentPosition).

例如,我的Web应用程序需要定位服务,并且用户无意中单击了阻止",或者他们改变了主意.我该怎么做才能再次提示他们?

For example, my web app requires location services, and the user accidentally clicks "block", or they change their mind. What can I do to prompt them again?

推荐答案

如@ matthew-shwery所述,您不能更改权限.
最好的办法是检查权限,并通知用户该权限被拒绝

As mentioned by @matthew-shwery, you can not change the permission.
the best you could do is check for the permission and notify the user is the permission is denied

navigator.permissions.query({
     name: 'geolocation'
 }).then(function(result) {
     if (result.state == 'granted') {
         report(result.state);
         geoBtn.style.display = 'none';
     } else if (result.state == 'prompt') {
         report(result.state);
         geoBtn.style.display = 'none';

         navigator.geolocation.getCurrentPosition(revealPosition, positionDenied, geoSettings);
     } else if (result.state == 'denied') {
         report(result.state);
         geoBtn.style.display = 'inline';
     }
     result.onchange = function() {
         report(result.state);
     }
 });

地理位置文档

这篇关于用户在javascript中阻止访问后请求位置坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆