I play a little with the iPhone SDK and I want to show the current speed in my application. There are so many applications that can do this very accurately, especially for low speeds such as running or cycling. The best I've seen is RunKeeper.
But in my application, the speed is absolutely inaccurate. At low speeds, it is always zero, and only at higher speeds does it show some values, but they are rarely updated and are not very useful.
- (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 have working code for this? Or can you tell me what's wrong with mine?
I would try the following.
, DistanceFilter wishAccuracy : - , .. , GPS, , GPS . Apple:
, . , , kCLLocationAccuracyBest . . , , . . , .
.
GPS . , , - .
-, : . , , .
-, : , getDistanceFrom(), , . . Apple .
, :
speedLabel.text = [NSString stringWithFormat:@"SPEED(Km/Hr): %f", [location speed]*3.6]; latitudeLabel.text = [NSString stringWithFormat:@"LATITUDE: %f", location.coordinate.latitude]; longitudeLabel.text = [NSString stringWithFormat:@"LONGITUDE: %f", location.coordinate.longitude]; CLLocationDistance meters = [location distanceFromLocation:orginalLoc]; distanceLabel.text = [NSString stringWithFormat:@"DISTANCE(M): %f", meters];