我有一个获取观众当前位置的功能。但是,我试图以这样的方式使它每次调用函数时都试图一次又一次地获取查看者的当前位置。我想这样做的原因是我的网页试图在加载时询问当前位置。如果观看者拒绝,查看我的网页并改变他们的想法,我需要他们能够再次尝试而无需重新加载页面。这是我到目前为止所得到的:
function getCurrentLocation(callback) {
if ( navigator.geolocation ) {
if ( typeof(locationId) == 'undefined' || locationId <= 0 ) navigator.geolocation.clearWatch(locationId);
locationId = navigator.geolocation.getCurrentPosition(function(position) {
currLocation = position.coords;
console.log('navigator - success');
if ( typeof(callback) != 'undefined' ) callback();
},function(){
console.log('navigator - fail');
if ( typeof(callback) != 'undefined' ) callback();
});
} else if (google.gears ) {
var geo = google.gears.factory.create('beta.geolocation');
if ( typeof(locationId) == 'undefined' || locationId <= 0 ) geo.clearWatch(locationId);
locationId = geo.getCurrentPosition(function(position){
currLocation = position;
console.log('gears - success');
if ( typeof(callback) != 'undefined' ) callback();
}, function(){
console.log('gears - fail');
if ( typeof(callback) != 'undefined' ) callback();
});
}
return currLocation;
}
由于一些奇怪的原因,在我点击“不允许”按钮后,导航器总是调用失败功能,并且从不尝试再次询问当前位置。我如何让它再次询问?