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

Java Development

Reply
Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified
Accepted Solution

GPS robustness in BB device

Hi guys, Recently I have faced with some gps problem in 8110, the 8110 does have a weaker gps chip and sometimes I could not get the gps information, so is it possible to refresh the GPS? (We can refresh GPS from the BB device menu(Option -> Advaced Options -> GPS -> Refresh GPS), but how can I refresh from the code) I mean how can I refresh the GPS from my code?
Developer
Posts: 20
Registered: ‎11-12-2008
My Device: Not Specified

Re: GPS robustness in BB device

Once you've obtained a LocationProvider from LocationProvider.getInstance(), you have two choices:

1) run a thread that polls the given provider every x secs;

2) register with provider.setLocationListener() and listen for callbacks on locationUpdated()

Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS robustness in BB device

I think this KB article may provide the answer you require.

 

How To - Detect when GPS is no longer available and when to reset the LocationProvider 
Article Number: DB-00577

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800703/How_To_... 

 

The following might be the key sentence in this article:

 

To do so, simply call reset() on the instance of LocationProvider, then either set the LocationListener to null, or register a new LocationListener.

Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: GPS robustness in BB device

Tnx Peter'

When GPS signal is weak, my application detects. To detect it, I am using following code  :

 

 


public void locationUpdated(LocationProvider provider, Location location) {
if(location.isValid()) {
//TODO something. Successfully.
} else {
//Detect here. My application counts invalid location.
//Call restart() GPS listener method.

restart();

}
}

 

Restart method body :

 

 

public void restart () {
gpsListener.stop();
gpsListener.start();
}

 

 

GPS listener stop method :

 

 

public void stop() { if (locationProvider != null) { locationProvider.reset(); locationProvider.setLocationListener(null, -1, -1, -1); locationProvider = null; } }

 

GPS listener start method :

 

 

public void start() { if (lp == null) { try { locationProvider = LocationProvider.getInstance(null); if(locationProvider != null) { locationProvider.setLocationListener(this, 2, 1, -1); } catch(LocationException e) { System.out.println("Exception : " + e.toString()); } } }

 

When GPS signal is weak, application calls restart() method. It doesn't work fine. In other word, can't receive GPS location.

 

And when I work Options => Advanced Options => GPS => "Refresh GPS" of BB device, can recieve GPS location.

 

So, I am searching better way to restart GPS reciever. Do you have any idea ? Maybe I mistook on source code. 

Please help me guys? 

 

Last question :  2 way to create LocationListener object. 

 

First one is :

locationProvider = LocationProvider.getInstance(null);

Second one is :

 
 Criteria c = new Criteria();
c.setHorizontalAccuracy(500);
c.setVerticalAccuracy(500);
c.setCostAllowed(false);
locationProvider = LocationProvider.getInstance(c);


What is difference of abobe 2 ways ?

Which one is better ?

 

Tnx guys'

 

Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: GPS robustness in BB device

What is Criteria class used for ?
Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS robustness in BB device

Your code for resetting the LocationProvider looks fine to me.  I was delaying responding in the hope that you would get other input into this issue.  Not sure that I can help any more other than suggesting upgrading the device to OS 4.5 to see if that helps.

 

Re your question on Criteria:

 

How To - Define criteria to retrieve a GPS fix
Article Number: DB-00461

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800703/How_To_...

Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: GPS robustness in BB device

Tnx Peter' I got it'

It was the cool'

Tnx again'

Developer
Posts: 39
Registered: ‎11-30-2008
My Device: Not Specified

Re: GPS robustness in BB device

Hmm, I must be missing something in your code:

 

 

locationProvider.setLocationListener(this, 2, 1, -1);

 

 Doesn't that set the timeout to 1 second for recieving a fix?  Isn't that way too short?  I must be missing something.

 

Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: GPS robustness in BB device

Tnx for ur response'

 

So, What do you think about how many it should be?

 

 

Developer
Posts: 39
Registered: ‎11-30-2008
My Device: Not Specified

Re: GPS robustness in BB device

I don't know really.  I'm still trying to confirm that I understand what the meaning of the timeout is.  I have mine currently set to -1 (for the default), I was thinking of setting it to 180 as I read somewhere it may take up to 3 means to obtain a fix from a cold start.

 

However, like I said I'm not a 100% sure the timeout setting effects getting the initial fix.