Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone CoreLocation: How to get the most accurate speed

I'm experimenting with adding the GPS functionality to my iPhone app. It's a workout app that will be used while walking or running. So what I want to use GPS for is to show the speed that the person is moving in Mph and minute/mile.

How should I configure the CLLocationManager so I get the best possible results? What should I set desiredAccuracy and distanceFilter?

I've tried with:

distanceFilter = 10 and desiredAccuracy = kCLLocationAccuracyNearestTenMeters

and reading

CLLocation.speed property

Testing while driving around in my car the accuracy seems good compared to the car speedometer although it takes a while to update. I realize that the update delay may very well be the time it takes to query the GPS location, but I'm not sure if changing the above two parameters would give better results.

Should I use kCLLocationAccuracyBest and some other value for distanceFilter?

I'm interested to hear from others using CoreLocation to get speed. What are you doing to get more accurate results?

like image 829
subjective-c Avatar asked Feb 24 '09 16:02

subjective-c


2 Answers

For best results, you should use kCLLocationAccuracyBest. What you put into your distance filter depends on up with which faults you're willing to put. Basically, you're going to have to make decisions based on accuracy vs availability. That is, during periods when a best-accuracy answer is not available, what will you display?

One approach is to let the phone deliver less-accurate answers and, using a projection of what was happening the last time you had best-accuracy information, see if what you have makes sense.

That is, suppose I'm jogging at 6mph to the North. You plot me along point-A, point-B, point-C... then you get a low-accuracy answer (maybe kCLLocationAccuracyNearest100Meters.) Look at the spot where it says I am and figure out "could I have gotten to that spot from point-C if I'd continued along my current path, making reasonable adjustments for possible changes in speed?" If so, then the new point is within the realm of possibility. (If not, then toss it out.) Then project from point-C at my last-known speed and figure out where you think I probably am, ballistically. Save that as ballistic-point-D.

Of course, you're using the accelerometer to get some sort of inertial sense of which way I went, right? So, you can't know direction (you don't know what way the phone is pointing), but you can make a reasonable stab at distance.

Using all this information, plot the most likely spot where you think I probably am.

NOTE: When testing, don't just drive in good-cell coverage areas. See how your app performs out in the hills, away from cell phones. A lot of people like to bike & jog those areas!

like image 109
Olie Avatar answered Sep 27 '22 22:09

Olie


Disclaimer: I've only played with CoreLocation a bit, I've not tested the accuracy very closely.

I'd expect that you'd get the most accurate results by using the defaults for distanceFilter and desiredAccuracy. Less-frequent updates are only going to give you less data to work with.

One issue you're likely to run into is when the location fix is lost for a while, then comes back. The naive, connect-the-dots approach to figuring out distance traveled is going to tend to under-estimate the actual speed of the runner. Rather than using CLLocation.speed, you might get better results calculating speed based on some heuristic approximation to the line the runner is actually following.

like image 36
Mark Bessey Avatar answered Sep 27 '22 21:09

Mark Bessey