Chrome 和 HTML5 GeoLocation 拒绝回调

google mapsweb developmentjavascriptfront end scripts

对于 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}
);

相关文章