I am getting a very stupid problem
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, ll);
float spd = myLoc.distanceTo(previousLocation) / (myLoc.getTime() - previousLocation.getTime());
previous location is the myLoc stored last time onLocationChanged was called i-e each after 1 second.
Now my problem is, sometimes it gives extremely big peak values. making spd go way higher than it usually is.
Anyone can tell how can i reduce this
Best Regards
A few recommendations:
Check
Location.hasSpeed()to see if this information is provided for you. It may be more reliable than your calculation, though I don’t know anything about the algorithm used to produce this value.Check
Location.getAccuracy()to decide when to ignore a particular fix for calculating speed.Read these tips thoroughly to see an example of how to be selective when dealing with GPS results. They could be too old or too imprecise to be used for speed. http://developer.android.com/guide/topics/location/strategies.html#Updates
For an app I worked on, I implemented a filter that compared the current location to the two previous locations and used the lowest calculated speed. You may need a more or less complex method to determine speed that will be useful for you.