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
canamgroup
Posts: 117
Registered: ‎07-16-2008
My Device: Not Specified
Accepted Solution

GPS coordinates are sometimes not accurate

Hi,

 

I've made a Java application some time ago that retrieves a GPS coordinate every 15 minutes from the Blackberry and sends it to a web server to be displayed on a map.

 

My application (both native application on Blackberry and map application on web server) works very well.  However, once in a while, I receive a GPS coordinate that is way off (sometimes even in the middle of the Atlantic ocean)!

 

It seems very random.

I've seen this problem on many different models (to name a few): Curve 8330, Curve 8530, Storm 9530 and even the Torch 9800.

 

It's very annoying! And not very professional (as users laugh when the point is in the water).

 

I've seen this post, which reports an identical problem:

http://supportforums.blackberry.com/t5/Java-Development/GPS-location-data-is-sometimes-not-accurate/...

 

I did try the suggestion to turn "Location Aiding" to "Off":

http://docs.blackberry.com/en/smartphone_users/deliverables/3045/Turn_off_location_aiding_400936_11....

 

It seems to help a bit, but the problem still happens sometimes.  It is particularly awful with one Curve 8530 (in the Mississauga area) where I receive weird GPS coordinates every day (in the middle of the ocean or up north).

 

I wanted to do a verification of the points in my code when the map receive them, but it's not an easy task. I have to compare the new point to the latest one... and check the distance (in km) between those two points and reject the last one if the distance between the two is impossible.  I've done this.... but I ran into problems when, for example, the Blackberry was down (or out of coverage, or gps unavailable or battery's dead) for many hours (I was then rejecting good GPS coordinates).

 

Is there something I could do to avoid this?

Someone has faced this before?

 

Thanks for your help!

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS coordinates are sometimes not accurate

I agree it is essential to do validity checking on the values returned.  I have heard about two different approaches

 

a) Take a number of values, throw away any that appear to be miles away, and then average the observations to get a result you are happy with. 

b) Validity check the location including against the last known good location.

 

I have attempted to implement (b), and in summary, here is what I check.

 

Step 1, attempt to discard or keep the latest value based on data with in itself

i) If the reading has 5 or more satellites, then it  has potential to be OK.  In general 4 is OK, but readings with 3 are dubious

ii) Check the height.  I have found that dodgy reading usually have impossible heights, like several kilometers in the air.  You need to be careful with this one because I believe some Storms used to report underground heights. 

iii) Not yet implemented, but I was considering checking the accuracy reported.  As I understand it, this is actually a standard deviation, i.e. there is 99% chance that the the value is the specified location plus or minus 3 of the figure given by the accuracy.  In theory therefore, if the accuracy is low (i.e. this value is high), you should throw away the value.

 

This checking will throw away any locations that are clearly not accurate. 

 

Step 2 - Decide if I need to compare the value with the previous acceptable location

i) Accept if the value has 6 or more satellites - I've yet to see a dud location with 6 satellites.

ii) Accept if there is no previous value, or the previous value was too long ago, or the GPS unit has been restarted, or device restarted.

 

If the location is not accepted, then the final step is to check it against the last acceptable value.   .

 

Step 3 - validity check the new location when compared with the old value

i) Calculate the distance traveled, divide by the time that has passed to calculate a velocity.  If this speed is within reasonable bounds, then accept the new reading.  Reasonable bounds will depend on the modes of transport that the people you are tracking regularly use. 

ii) Be wary of sudden changes in height.  The coordinates calculation does not factor height in when calculating distance, so you can do this yourself. 

 

If it passes this checking, the keep the new value and use it as the 'previous acceptable value' when checking the next location. 

 

Hope this helps.

Please use plain text.
Developer
canamgroup
Posts: 117
Registered: ‎07-16-2008
My Device: Not Specified

Re: GPS coordinates are sometimes not accurate

Thanks Peter for your useful and detailed answer, as always.

Here are a few follow-up questions, if you don't mind.

 

I assume Step 1 must be done on the Blackberry application side, as the Web Server side just receives pin/date/lat/lng.  I just did a new development in my Map application, but I tried to avoid modifying my Blackberry application, but I guess I will need to do as well.

 

I have already implemented Step 2.2, but this is exactly where my problem is.  If there's no previous value, of if the previous value is a long time ago, I don't have any choice but to accept it.  And believe it or not, but it happened twice that this point was incorrect (in the middle of the ocean), but I had to accept it.  And even worst, I then rejected every other points (but they were good) because they were miles away from that last accepted point (ocean).  Again, I guess my only solution is to implement Step 1 inside my Blackberry application and hope that this validation will reject it at the source.

 

If you're curious, here's what I'm doing right now to accept/reject points (all done on my Web Server)

- When I receive a point, I check if there's a previous point, if not, I accept it.

- If there's a previous point, I calculate the distance (dist) between those two points by using a formula I found here (not considering hills though... direct distance):

http://www.movable-type.co.uk/scripts/latlong.html

- I then calculate the time (diff) between those two points (in seconds).

- I set a limit (limit) that a truck can drive to 150 km/h (impossible to do).

- Then if this condition is true, I reject the coordinate:

if (dist > (diff/60/60)*limit)) { ... reject... }

 

So, If the truck drove more than 150km/h, I reject it.

But let's say there's 10 hours between the current point and the last accepted one, the trucker could have travelled 1500 km, which could be anywhere.  I'll accept that coordinate, but it could have been an invalid one.

 

So It's more compicated than I thought :smileyhappy:

I'll try to implement your suggestions and hope for the best.

 

BTW, is it a problem specific to Blackberry, or it could happen also with iPhone, Android, and real GPS devices?

 

Thanks again!

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS coordinates are sometimes not accurate

[ Edited ]

I actually do all that processing on device - there is no point sending in data to be thrown away!

 

I would encourage you to throw away readings with 4 or fewer satellites.  And as noted, if you have 6 or more satellites, then I'd be very very confident that the value is OK and would not even bother checking with the previous one.

 

So you are only worried about the values with 5 satellites.  In my experience on BlackBerry devices, these are sometimes good and sometimes not.  Distance and height seem to be good checks, when the times are reasonably close.  When they are not, then I would actually argue that you should wait until you get a value with 6 satellites before starting recording.  If you have missed 10 hours, missing another minute is not going to be that worrying.

 

That said, your Server side validity checking seems similar to mine. 

 

Note that if you are using a location listener, in my experience it actually creates one location, and then updates it, so you must clone the location that you get, otherwise it will geet updated by the next value that is passed to you.  You've probably already spotted that. 

 

Re other phones, look at these:

http://stackoverflow.com/questions/2872307/iphone-gps-logging-inaccurate

http://groups.google.com/group/android-developers/browse_thread/thread/685fee810e18b7f9

Please use plain text.
Developer
canamgroup
Posts: 117
Registered: ‎07-16-2008
My Device: Not Specified

Re: GPS coordinates are sometimes not accurate

Thanks Peter!

 

Just for your information, I'm not using a LocationListener, but a Timer (every 15 minutes) with a .getLocation.

 

All you're saying make sense to me!

 

I really apreciate your help.

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS coordinates are sometimes not accurate

On that case, I would start a LocatinListener every 15 minutes, and get a number o f values and stop it when you are happy.  Start it with something 10 seconds between updates, then you should get a number of values you can sample from quite quickly.  Stop if they are being consistent or you get a 6 or more satellite reading. 

 

Just a thought. 

 

Good luck.

Please use plain text.
Developer
canamgroup
Posts: 117
Registered: ‎07-16-2008
My Device: Not Specified

Re: GPS coordinates are sometimes not accurate

I think, since I already need to modify my code, that I should probably modify it to include a LocationListener instead (since I'm getting multiple fixes at a regular interval).

 

Thanks again for your valuable answers!

 

 

Please use plain text.
Developer
canamgroup
Posts: 117
Registered: ‎07-16-2008
My Device: Not Specified

Re: GPS coordinates are sometimes not accurate

Oh, are LocationListener used only when GPS fixes are required for a short interval (ex: 10 secs)?

Or Is it OK to use a LocationListener with an interval of 15 minutes?

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS coordinates are sometimes not accurate

I don't see why you couldn't but I probably wouldn't.  Just a style thing. 

Please use plain text.