views:

1246

answers:

2

Hello,

I´m playing a bit with the iPhone SDK and I want to show the current speed in my Application. There are so many Apps that can do that really precise, espacially for low Speeds like running or biking. The Best I´ve seen is RunKeeper.

But in my Application the Speed is absolutely inaccurate. In Low Speeds is always null and only at higher speeds it shows some values but they are rarely updated and noot really usefull.

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation {
if (newLocation.timestamp > oldLocation.timestamp &&
 newLocation.verticalAccuracy > 0.0f &&         // GPS is active
 newLocation.horizontalAccuracy < 500.0f &&         // GPS is active
 //newLocation.horizontalAccuracy < kCLLocationAccuracyHundredMeters && // good quality GPS signal
 //newLocation.speed > 1.0f &&           // enough movment for accurate speed and course measurement
 oldLocation != nil)              // oldLocation is nil on the first reading
{
 double speed = (newLocation.speed * 3.6);
 [self updateDisplayWithSpeed:speed];
 //double direction = newLocation.course;
}

}

Does anyone has working Code for that? Or can tell me what´s wrong with mine?

Thank you so much

twickl

+2  A: 

I would try the following.

Remember that you should set the distanceFilter and desiredAccuracy as needed by your scenario: walking is not the same as traveling by car etc. Moreover, when you request high accuracy from the GPS, you must always discard the very first location provided by the GPS and use the second one as the starting location. Quoting the Apple documentation:

You should assign a value to this property that is appropriate for your usage scenario. In other words, if you need only the current location within a few kilometers, you should not specify kCLLocationAccuracyBest for the accuracy. Determining a location with greater accuracy requires more time and more power. When requesting high accuracy location data, the initial event delivered by the location service may not have the accuracy you requested. The location service delivers the initial event as quickly as possible. It then continues to determine the location with the accuracy you requested and delivers additional events, as necessary, when that data is available.

Here is my suggestion.

First, update the location using the GPS using an interval of at least one second. Below this interval the speed value is useless because it is measured in meters per second and owing to the previous discussion, you are not likely to get a valid update in less than a second with high accuracy.

Second, only use meaningful values for the location coordinates: you should discard values with negative horizontalAccuracy. This is what I am referring to when speaking of good locations.

Third, you can compute the distance by yourself: compute the distance between the last good location and the previous good location using getDistanceFrom() and then divide by the number of seconds elapsed between the location update. This will give you the distance in meters per second. I will try to do this and compare the result with the Apple provided speed.

unforgiven
A: 

? so..... what the best way ? anyone help me ?

Thanks a lots.

Robin