除了第一次设置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());