HTML5 离线模式和地理定位

发布于 2024-09-18 09:07:22 字数 141 浏览 9 评论 0 原文

当您在 HTML5 中处于离线模式时,是否仍然可以使用地理定位功能?看来当我在线时(navigator.onLine = true),地理位置工作正常。但是当我离线时(navigator.onLine = false),我会被抛出错误回调,并且错误表明地理位置不可用。

Is it possible to still use the geolocation features when you are in offline mode in HTML5? It appears that when I am online (navigator.onLine = true), the geolocation works fine. But when I go offline (navigator.onLine = false), I get thrown to my error callback and the error indicates geolocation not available.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

肤浅与狂妄 2024-09-25 09:07:22

这将取决于特定浏览器中地理位置的连接方式。在 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.

你穿错了嫁妆 2024-09-25 09:07:22

同意@robertc。 Navigator 对象确实可以在移动浏览器中通过 GPS 访问地理定位。

对于那些通过移动浏览器寻找离线地理定位的人这个 cordova 插件可能会有所帮助。

它基于W3C 地理定位 API 规范

其中规定:

“本规范仅限于提供脚本 API,用于检索与托管设备关联的地理位置信息。”

我已经实现了,即使您没有:活动网络,它也能正常工作,它可以从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.

It is based on the W3C Geolocation API Specification

Which says:

"This specification is limited to providing a scripting API for retrieving geographic position information associated with a hosting device."

I have implemented and it is working well even if you don't have: active network, it can fetch geolocation from GPS.

dawn曙光 2024-09-25 09:07:22

我真的没有答案给你,但你可以尝试在 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.

白鸥掠海 2024-09-25 09:07:22

今天到 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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文