Under low accuracy situations, I’ve noticed on both iPhone and Android that the GPS location can fluctuate wildly over a short period of time, sometime jumping 2500 ft (762m) or more within several seconds. By low accuracy I mean the GPS result indicated a horizontal accuracy of greater than 1000ft (305m). This creates a really poor user experience, so I quickly implemented a very rough algorithm to minimize these fluctuations. Here’s some psuedo-code that demonstrates the concept:
private _currentTime:Date; private _lastUpdateTime:Date = null; private const _DISTANCE_ACCURACY_THRESHOLD:Number = 2500; //feet private const _TIME_ACCURACY_THRESHOLD:Number = 1000; //msecs _timer = new Timer(100,0); _timer.addEventListener(TimerEvent.TIMER,function(event:TimerEvent):void{ _currentTime = new Date(); }); _timer.start(); //Calculate time elapsed since last update var f:Number = _currentTime.time - _lastUpdateTime.time; if(_lastUpdateTime != null) { //Minimize annoying fluctuations. //accuracy is a property from GPS result (horizontalAccuracy) if(f >= _TIME_ACCURACY_THRESHOLD && accuracy <= _DISTANCE_ACCURACY_THRESHOLD) { isValid = true; } else { _lastUpdateTime = _currentTime; } }
The theory is that the distance and time between fluctuations calculate out to speeds greater than 2500 ft/1 second. You can adjust the parameters as you see fit. I also assumed that under normal driving (or walking!) conditions you wouldn’t be going that fast, right?
You could also write a native extension, but I didn’t have enough time to do that. The native Android SDK offers many ways to use the GPS that could eliminate these problems.
This could certainly use some tweaking, so if you have suggestions for improvement please post a comment or send me an email!