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
Contributor
Utente
Posts: 13
Registered: ‎01-21-2013
My Device: BB 10
My Carrier: -

Is GPS turned on ?

Hello!

 

Is there any way to check if the user allowed the application to use the GPS ?

How can i check if the GPS is enabled on te device ?

 

I've tries this

 

window.navigator.onLine

 

but it just returns true at any time.

 

Please use plain text.
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: Is GPS turned on ?

That call tells you if your web browser can talk to the device

 

You're after this stuff




Click the like button if you find my posts useful!
Please use plain text.
Contributor
Utente
Posts: 13
Registered: ‎01-21-2013
My Device: BB 10
My Carrier: -

Re: Is GPS turned on ?

Hmm, thanks for the answer.

I was using navigator.geolocation.watchPosition to get the position.
However, it works properyly when the GPS is enabled, but it just doesn't call the callback error function when GPS is disabled.

IMHO it should call the error callback and return PERMISSION_DENIED as error.


This is my code:

 

navigator.geolocation.watchPosition(function(){

    alert("I found you!");

},

function(error){

    alert("Why I'm never called ?");

},

{ timeout: 10000});

 

The code works well on Ripple, but on BB 10 alpha the error callback is never called.

Please use plain text.
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: Is GPS turned on ?

This is beginning to get annoying (not your fault)

 

BB have obviously announced a launch that ain't happened yet

 

Yes we have something similar and yes you'll be able to use your existing code someday soon as I understand it

 

They're in the progress of making the two APIs one but right now this is not the case.

 

I'll go moan to one of the people in the know @ BB + get back to you




Click the like button if you find my posts useful!
Please use plain text.
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: Is GPS turned on ?

I've contacted BB, he suggested I run up a version as it's standard HTML5

 

Before I do this can I ask a very silly question

 

Are you testing the app indoors?

 

You can't get a GPS location without clear line of sight to the satellite.

 

Apple and Droid fake it by saving your last known point - try it - take a droid or iOS device, get a fix - stck it in a metal tin (gaussian cage) - move a few hundred yards - you're still where you were until GPS locks on again.

 

If you're inside the callback will never happen, your timeout will stop it looking after 10 seconds so you should prob let the use know




Click the like button if you find my posts useful!
Please use plain text.
Administrator
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Is GPS turned on ?

I don't believe this is possible in the browser.  The HTML5 spec for geolocation does not have a "permission" API as far as I know.  You would need to include error support to handle timeouts or failures in this case.

 

However, for the same content running in a WebWorks app container, you may be able to get closer to what you want

 

Try using this :

 

var isCapable = blackberry.system.hasCapability("location.gps");

 

http://developer.blackberry.com/html5/apis/blackberry.system.html#.hasCapability

 

This feature normally returns true if the device has GPS hardware.  However, I'm not entirely sure if it returns false if the user disables the GPS application permission.  Suggest trying it and posting back here with the results.

 

Does anyone know?  I haven't yet tried this myself.

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