HTML5 navigator.geolocation in Web Workers

后端 未结 4 474
温柔的废话
温柔的废话 2020-12-07 01:47

I am trying to move my code for navigator.geolocation in a web worker.

I tried it with Chrome and Safari but getting \'undefined\' on

var isGPSSupported =

4条回答
  •  悲哀的现实
    2020-12-07 02:18

    The 'navigator' object is supported, however it only contains four properties: appName, appVersion, userAgent, and platform.

    From looking at your code, it appears you are trying to track the user's location as it changes. You do not have to use web workers to accomplish this. You can simply monitor the user's location on the main thread using watchPosition(), which will automatically notify a callback function whenever the user's location changes:

    navigator.geolocation.watchPosition(function(position) {
        document.getElementById('currentLat').innerHTML = position.coords.latitude;
        document.getElementById('currentLon').innerHTML = position.coords.longitude;
    });
    

提交回复
热议问题