Using Geolocation in HTML5 Web Worker

I want the HTML5 web worker to report longitude and latitude to a calm server at regular intervals - even if the tab is not in focus. My problem is that the way I usually access the HTML5 geolocation function is not available to the web worker.

What I tried sends the geolocation object from my main file to the web worker. However, this did not work, and I received the following error:

Uncaught DataCloneError: Failed to execute 'postMessage' in 'Worker': Object cannot be cloned.

Next, I tried to import a JavaScript library that provides geolocation services called Geolocator . But then I discovered that I do not have access to the library for the worker (I think because the worker does not have access to the DOM).

So, trying to deal with this, I added the source of this JavaScript library directly to the working file, but this did not work, because I do not have access to window, which is used in all sources of Geolocator .

Am I trying to do this? Are there any alternatives that I can use?

+4
source share
2 answers

navigator geolocation, .

navigator, WorkerNavigator, navigator .

WorkerNavigator geolocation, geolocation , , geolocation -. .

+4

, . Firefox ( ) , W3C/IETF.

, , , , , .

0

All Articles