对于Google Chrome中的超时回调,请尝试以下代码:
_callback = false; function successCallback(position) { _callback = true; console.log('success'); } function errorCallback(error) { _callback = true; alert('error'); } setTimeout(function(){if(!_callback)console.log('ignored')}, 20000); navigator.geolocation.getCurrentPosition( successCallback, errorCallback, {timeout: 2000} );