I'm working on something similar on Andoriod, but the principals are the same for iOS either:
- For each GPS sample, check its accuracy. If it's over some threshold (say 20 meters) - ignore it.
- Remember that even if the mobile device is static, different GPS samples will give you different locations, depending on the accuracy. A car standing still for a long time in a traffic light, will show that you've advanced few dozens of meters, so add a method that detects if the mobile is static or not. I've implemented this by reading the accelerometer - if the delta between two readings if bigger than some threshold - the device is moving. If it's too small - ignore the GPS.
- If you intend to use it in a car, you can read the GPS whenever it has a new reading (in Android use the
onLocationChanged
method). If you use it for running/walking, take into account that your speed is slow - two consecutive readings will be relativly close, but due to the GPS's accuracy, you can get quite a large distance betwwen them. It can be fixed by increasing the time between two consecutive readings, or by ignoring some of them (i.e. take into account only each 10th reading).
- Use the Haversine formula to calculate the distance between two consecutive readings. In Android it can be done with the
Location.distanceTo()
method.
You'll have to test it against the odometer in your car and adjust the thresholds for the accelerometer.