HTML5 离线模式和地理定位
当您在 HTML5 中处于离线模式时,是否仍然可以使用地理定位功能?看来当我在线时(navigator.onLine = true),地理位置工作正常。但是当我离线时(navigator.onLine = false),我会被抛出错误回调,并且错误表明地理位置不可用。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这将取决于特定浏览器中地理位置的连接方式。在 Firefox 中,GeoLocation 取决于 Google 位置服务 通过将一些网络信息发送到网络服务来工作 - 显然,当您离线时,这将不起作用,因为网络服务将不可用。
如果您有一个直接与 GPS 硬件通信的浏览器,那么它可以离线工作,但我认为您不会找到任何具有这种集成功能的桌面浏览器 - 也许一些移动浏览器会。
It's going to depend on how the GeoLocation in that particular browser is wired up. In Firefox, GeoLocation depends on Google Location Services which works by sending some network information to a web service - obviously this is not going to work when you're offline as the web service will not be available.
If you had a browser which communicated directly with GPS hardware then it would work offline, but I don't think you'll find any desktop browsers with that sort of integration - maybe some mobile ones will.
同意@robertc。 Navigator 对象确实可以在移动浏览器中通过 GPS 访问地理定位。
对于那些通过移动浏览器寻找离线地理定位的人这个 cordova 插件可能会有所帮助。
其中规定:
我已经实现了,即使您没有:活动网络,它也能正常工作,它可以从GPS获取地理位置。
Agreed with @robertc. Navigator object does access geolocation from GPS in mobile browsers.
And for those who are looking for offline geolocation through mobile browser this cordova plugin might help.
Which says:
I have implemented and it is working well even if you don't have: active network, it can fetch geolocation from GPS.
我真的没有答案给你,但你可以尝试在 PositonOptions 结构中设置一个较高的 MaximumAge ,看看它是否至少会给你一个过时的答案。
I don't really have an answer for you, but you might try setting a high maximumAge in the PositonOptions structure to see if it will give you an out of date one at least.
今天到 2013 年 8 月 3 日,经过数百次测试和 PhoneGap + HTML5 尝试后,浏览器上的离线地理定位根本不起作用。如果有人让它工作,请告诉我们如何......
Today by August 3rth 2013, Offline Geolocation on browsers simply DO NOT WORK, after hundres of tests and PhoneGap + HTML5 tries. If anybody makes it work please tell us how....