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
Regular Contributor
Posts: 64
Registered: ‎02-03-2010
My Device: Bold
My Carrier: Orange

Refresh GPS in settings working better than LocationListener

Hello - I'm developing a location based app. Usually it takes a lot of time for 

my app to find the first GPS fix. I saw a post in forum by peterStrange 

that it can take up to 5 minutes 

http://supportforums.blackberry.com/t5/Java-Development/why-should-quot-Refresh-GPS-quot-first/m-p/5...

Is this indeed the case? 5 minutes is ALOT. 

 

Anyway, i would have settled with accepting that, since it complies more or less to the behavior i see in my app, but i decided to do some further checks. Usually when my app doesn't have GPS, and i go to settings -> advances -> location ->refresh GPS, 

it still takes some time to get GPS signal, but certainly less than the time it's taking my app. When the refresh GPS returns, my app is updated with the new location. So could refresh GPS somehow be performing something better than me?

 

My code : 

 

My Criteria settings : 

 

 

 Criteria cr = new Criteria();
 cr.setPreferredPowerConsumption(Criteria.NO_REQUIREMENT);
 cr.setSpeedAndCourseRequired(true);

 To my understanding this should allow the Assisted GPS mode, and should be as enabling as the refresh GPS...

 

Then get the Location using the Location Listener : 

 

 

provider.setLocationListener(this, 1, 1, 1);

 So i get the GPS every max 2 seconds. The problem is that the location i get is always not valid until i refresh the GPS, or until a long time passes... 

 

Any Ideas anyone?

 

 

Thanksalot

 

Dan

 

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

Re: Refresh GPS in settings working better than LocationListener

Until the GPS chip is actually hot, getting a value every second is not going to happen. 

 

So you basic processing loop with GPS goes something like

 

1) Set Criteria

2 ) LocationProvider.getLocation(int timeout), for as long as it takes,  there is no point continuing until you get a valid location from this

3) Set LocationListener

4) In location Listener, if you do not get a valid result for a period, say a few minutes, then reset the LocationProvider and go back to step 2. 

 

Review the RIM documentation, it is, from memory, fairly clear on this point and the fact that you need to reset the LocationProvider you loose GPS, which is relatively easy to do, for example, whenever you go into a building, car, plane or train. 

 

You will find a couple of good videos on this as well if you wonder round the resources section of the developer web site.   

Regular Contributor
Posts: 64
Registered: ‎02-03-2010
My Device: Bold
My Carrier: Orange

Re: Refresh GPS in settings working better than LocationListener

Thanks peter.

 

I see there is no point in setting the location listener until the first GPS is set - but 

do you think it can actually cause harm, besides the small overhead? (Could the location listener do strange stuff, instead of just doing it's internal getLocation at the designed interval? )

 

 

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

Re: Refresh GPS in settings working better than LocationListener

"do you think it can actually cause harm,"

 

You need to review the RIM documentation.  There are some comments about not doing certain things because it causes the Location Provider to reset', i.e. go cold.  If it does that, then you will wait for another x minutes.  I wonder if you specifying a timeout of 1 second on your Location Listener will tell the GPS processing to reset if it can't get a location every second, so every second it will go cold.  Don't know myself. 

 

Even if it doesn't cause any harm, it has no value, and you will feed loads of invalid values in your Location Listener, so what is the benefit?

 

I actually think a location every second is way overkill.  How far can a BlackBerry go in a second?  Remember that you will find even in good GPS the error you get is meters, perhaps 100's of meters, so I don't think this is achieving anything anyway.  I would use 10 seconds, as this is the maximum you can use that keeps the GPS hot.  Even in 10 seconds the Blackberry will typically not go far enough for the movement to just be 'error'. 

Regular Contributor
Posts: 64
Registered: ‎02-03-2010
My Device: Bold
My Carrier: Orange

Re: Refresh GPS in settings working better than LocationListener

Thanks again peter. 

 

The only reason not to make the change to your suggested mechanism, is programmer laziness, or more accurately the need to meet deadlines set from up above Smiley Happy 

 

Regarding your comment at 1 second being too frequent - The application is a turn-by-turn navigation - When driving 90 m/ph, you can cover quite a lot of distance in 10 seconds. All in all, getting the GPS every second proves itself to be working quite well. 

 

 

Developer
Posts: 656
Registered: ‎02-03-2010
My Device: Z10 LE
My Carrier: Rogers

Re: Refresh GPS in settings working better than LocationListener

I would test the battery drain with this app, as I expect it to be very high.  If the app consumes more than 5-10% of the battery per hour then the user is not going to be very happy.


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Developer
Posts: 588
Registered: ‎05-29-2009
My Device: 9100

Re: Refresh GPS in settings working better than LocationListener

But i have heard that using multiple and single fix at the same time is not a good practice. And when you do 2) and then 3) I think you are doing this. Maybe this can cause problems at some point.

Regular Contributor
Posts: 64
Registered: ‎02-03-2010
My Device: Bold
My Carrier: Orange

Re: Refresh GPS in settings working better than LocationListener

yes the battery is... drained Smiley Happy But this is something users in Turn-by-turn

navigation apps, (should) expect. Not much to do in that area. Anyway, users are relatively happy. 

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

Re: Refresh GPS in settings working better than LocationListener

I have read and heard nothing about using multiple and single fix causing problems at the same time.  And logically, I can see no reason why they would. 

 

Re battery drain, someone doing turn by turn in their car will probably have a car kit anyway,

 

My experience, using 9 or 10 second refreshes, suggests that a BlackBerry with a good battery can last almost a whole day with this.    By way of contrast, a BlackBerry which is busy doing network activity may only last 1/2 day. 

Developer
Posts: 588
Registered: ‎05-29-2009
My Device: 9100

Re: Refresh GPS in settings working better than LocationListener

I can tell you I was having problem with my application running under some OS and devices and I contacted RIM staff. They recommended me not to use both modes at the same time, and i after that my application worked out much better.

 

I also think that 10 seconds can give you a good accuracy and a not too bad battery performance.