如何使用所有 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());
如果您需要检查,这是 jsfiddle