html5 – 有没有一种检测用户是否已经有权限使用navigator.geolocation的方法?

除了第一次设置cookie之外,还有一种方法可以检测用户是否已经授权navigator.geolocation返回浏览器的lat / long?

如果有,所有浏览器是不同的,在所有浏览器中是不同的?

这个问题已经是partially answered elsewhere

根据GeoLocation API – Chrome / Safari – Permission management and Visual Differences,Chrome要求可撤销一次性许可.我还没有阅读这篇文章,但似乎存储权限不是纯Chrome的事情.

解决方法

如何使用所有html5浏览器(支持geoLocation)支持的localStorage?
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(successFunction,errorFunction);
} 
//Get latitude and longitude;
function successFunction(position) {
    var lat = position.coords.latitude;
    var long = position.coords.longitude;

    localStorage['authorizedGeoLocation'] = 1;
}

function errorFunction(){
    localStorage['authorizedGeoLocation'] = 0;
}

function checkauthorizedGeoLocation(){ // you can use this function to know if geoLocation was previously allowed
    if(typeof localStorage['authorizedGeoLocation'] == "undefined" || localStorage['authorizedGeoLocation'] == "0" ) 
        return false;
    else 
        return true;
}

然后您使用以下功能检查:

alert(checkauthorizedGeoLocation());

This is the jsfiddle if you need to check

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


h5页面是什么意思
html5复合选择器都有哪些
什么是html5响应式布局
h5页面制作策划怎么做
html5关系选择器有哪些
h5有哪些缓存机制
position中的sticky如何使用
h5页面制作用什么软件
h5链接怎么做
html5层次选择器有哪些
h5是什么意思
localstorage有哪些方法
h5怎么制作点击图标
h5怎么制作倒计时
h5怎么生成链接
h5表格边框怎么设置
h5兼容问题怎么解决
h5怎么做交互设计
h5怎么做进度条
h5怎么加链接