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
colombus
Posts: 264
Registered: ‎06-04-2009
My Device: Not Specified

GPS distance calculator

Hi,

 

I am developing an application to calculate the distance when user runs or walks. There are similar apps available in app world like endomondo, GPS speedo meter etc. Which is the best practise to implement this. Is it better to use a location listener and get the location every 1-5 second and use the haversine formula to find the distance or using a timer task to get the current location without location listener every 1-5 second and using haversine formula. Do both these approaches have any difference. Which will be the best approach for my use case.

 

Any other apporach to get more accurate distance will be helpful.

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

Re: GPS distance calculator

[ Edited ]

There are actuallly two questions here:

 

1) use location Listener or get current location?

Use a Location Listener.  just be prepared to restart the Location Provider should there be any issues.  Refer to this if you haven't seen it already;

http://supportforums.blackberry.com/t5/Java-Development/Location-APIs-Start-to-finish/ta-p/571949

 

2) How to calculate distance?

Anything wrong with the Coordinates.distance(...) method?

 

A word of caution.  I suspect you will find that the 'jitter' you get with GPS locations will be significant, you can apparently move significant differences in subsequent GPS locations even when you are not moving at all.  You might want to try to factor this out by checking the accuracy and/or averaging a number of GPS locations and/or checking the realms of possibility before you start using a location to calculate the distances.  So do not expect to be able to take every GPS location you receive at face value.  Some will be wildly inaccurate. 

Developer
colombus
Posts: 264
Registered: ‎06-04-2009
My Device: Not Specified

Re: GPS distance calculator

Thanks Peter,

 

I didnt get the following point 

 

"A word of caution.  I suspect you will find that the 'jitter' you get with GPS locations will be significant, you can apparently move significant differences in subsequent GPS locations even when you are not moving at all.  You might want to try to factor this out by checking the accuracy and/or averaging a number of GPS locations and/or checking the realms of possibility before you start using a location to calculate the distances.  So do not expect to be able to take every GPS location you receive at face value.  Some will be wildly inaccurate. "

 

Are you referrring to the case where the device is kept idle keepingthe gps on and te distance get updated .

Is there any way to overcome this. Can we use location.getSpeed()>0.0 condition to find whether the device is moving.?

Can the accuracy be checked based on the stellites count & signal strength? Is it a good method to average the number of  gps locations. please suggest to check the accuracy of the location.

 

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

Re: GPS distance calculator

The best way to see this is to try it.

 

If you collect all the GPS locations you get feed from the Location Listener, and just do a distance for each, you will find (or at least I found) that you can move 100 meters, even when the device is stationary.  I believe this is a factor of the number of the satellites and the position of these.  If you look at the QualifiedCoordinates that you will get from the Location, you will find accuracy figures.  Take care how you use them, I think they represent 1 standard deviation on a normal Bell curve, so for example so you can be 96% sure that the actual location is within 2 standard deviations in any direction.  

 

As a loose rule of thumb, I recommend that ignore anything that has fewer that 5 satellites, and has a significant change in altitude - this seems to be a good indicator of a dodgy reading. 

 

I have never looked at correlating the accurateness of the position and the satellite signal strength, though that sounds like a useful thing to do.  I think the speed and direction are calculated based on the location so if the location is dodgy, this might be as well.  But I have never looked at this either. 

 

I don't have a good answer for you sorry, we used to have a tracking application but we stopped supporting it so I do not have current experience in this area. 

 

If I was starting again now, I would try a rolling average over a period of time.  So get locations every 3 seconds or so, throw away any dodgy ones, then average the values you have over the last 15 seconds if running, or longer if walking.  .