繁体   English   中英

禁用设备位置时navigator.getCurrentPosition出现javascript问题-没有回调

[英]javascript issue with navigator.getCurrentPosition when device location is disabled - no callback

我正在尝试通过获取用户位置

navigator.geolocation.getCurrentPosition(this.check_location.bind(this), this.on_get_position_error.bind(this), { enableHighAccuracy: true, timeout: 5000 });

它在大多数情况下都能正常运行。 但是,如果在设备设置中禁用了地理位置定位(例如,在iPhone上:“设置”应用程序>“隐私”>“位置服务”>“关闭”) ,则Safari或Chrome将不会调用任何回调( this.check_location()this.on_get_position_error()不会) 。

任何想法 ?

谢谢

好的,所以我修复了它。 我不明白为什么,但是添加0延迟超时可以使其工作:

setTimeout(function() {

navigator.geolocation.getCurrentPosition(this.check_location.bind(this), this.on_get_position_error.bind(this), { enableHighAccuracy: true, timeout: 5000 });

}.bind(this), 0);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM