views:

2618

answers:

4

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?

+1  A: 

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.

Mark Bessey
+2  A: 

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!

Olie
A: 

Hi, I need your help, I am also doing the similar work, like calculating the travelling speed in MPH after every 2 seconds, But i am not sure hoe to do this.

Can you please share your code. I will be very thankful to you.

FAWad
A: 

hi, i also need your help in calculating speed .I am making an application which collects data while user is jogging and data is all GPS attributes(like longitde, latitude,altitude etc.).All data am getting fine ,bt speed provided by API(cllocation.speed) is always zero.i just need to know wheather it is a drawback with api or there is always we need to calculate speed by some maths formula (distance/time) for joggers. Can you please help me asap.. thanks in advance

Rchaudhary