HTML5 offline mode and geolocation

谁都会走 提交于 2019-12-13 12:26:50

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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....




回答5:


is it available at present or not? I am working on cordova android app but unable to get geolocation in offline mode. it is coming in online mode but in offline only sometimes it is giving the value last obtained when it was online which consumed me that it was working.



来源:https://stackoverflow.com/questions/3693256/html5-offline-mode-and-geolocation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!