06-22-2010 05:22 AM
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
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_REQUIR
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?
06-22-2010 05:43 AM
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.
06-23-2010 07:04 AM
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? )
06-23-2010 07:18 AM
"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'.
06-23-2010 08:25 AM
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
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.
06-23-2010 03:53 PM
06-24-2010 02:40 AM
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.
06-24-2010 03:26 AM
yes the battery is... drained 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.
06-24-2010 04:00 AM
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.
06-24-2010 04:06 AM
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.