Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
New Contributor
Posts: 6
Registered: ‎07-16-2012
My Device: Torch 9860
My Carrier: Telus

Moving navigator.geolocation into Web Workers

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

 

I tried it with Chrome, Safari, Ripple and Torch device but getting 'undefined' on

var isGPSSupported = navigator.geolocation;

 

Frustrated... 'navigator' object should be supported in web workers...

 

Anybody had any luck with this?

 

My code is below:

 

index.js

 

var gpsWorker = new Worker("app/gpsworker.js");

gpsWorker.onmessage = function(e) {

      alert(e.data);

};

gpsWorker.postMessage("Start GPS!");

gpsWorker.onerror = function(e) {

       alert("Error in file: " + e.filename + "\nline: " + e.lineno + "\nDescription: "+ e.message);

};

 

gpsworker.js

 

self.onmessage = function(e) {

     initGeoLoc();

}

function initGeoLoc() {

    if(navigator.geolocation) {

        navigator.geolocation.getCurrentPosition(function(position) {

             self.postMessage("Got position!");

        });

     }else{

        self.postMessage("GPS is not supported on this platform.");

     }

}

 

Any hint on what is wrong will be greatly appreciated.

 

Thanks you.

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Moving navigator.geolocation into Web Workers

Are you seeing the undefined error from  the "navigator" object or the "navigator.geolocation" object?  If the latter, I believe that is expected as from what I read in developer documentation, it appears that only the appName, appVersion, platform, userAgent properties are available.

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
New Contributor
Posts: 6
Registered: ‎07-16-2012
My Device: Torch 9860
My Carrier: Telus

Re: Moving navigator.geolocation into Web Workers

Hi,

 

Thank you for response. Yes, I have “undefined” on navigator.geolocation.

 

I am kind of confused Smiley Surprised it is not implemented because it was said in a lot of places in internet  geolocation should be available in web workers.

 

Can you please give me a link on docs you mention?

 

Thank you.

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Moving navigator.geolocation into Web Workers

I'll admit, there is a lot of mixed info our there.

 

The closest 'official' documentation I can find to this does not include any reference to relevant sub properties:

http://www.w3.org/TR/workers/#workernavigator

 

What I did find was more anectdotal evidence that suggests there is no 'geolocation' object availalbe within a worker - just certain properties:

https://developer.mozilla.org/en/Using_web_workers#Accessing_the_navigator_object

http://www.html5rocks.com/en/tutorials/workers/basics/

http://stackoverflow.com/questions/11533838/html5-navigator-geolocation-in-web-workers

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.