It looks like you're new here. If you want to get involved, click one of these buttons!
@protocol MyCLControllerDelegate
@required
- (void)locationUpdate:(CLLocation *)location;
- (void)locationError:(NSError *)error;
- (void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation;
@end
@interface MyCLController : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
id delegate;
int updateCount;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, assign) id delegate;
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation;
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error;
@end
#import \"MyCLController.h\"
@implementation MyCLController
@synthesize locationManager;
@synthesize delegate;
- (id) init {
self = [super init];
if (self != nil) {
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self; // send loc updates to myself
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if (updateCount < 2) {
[self.delegate locationUpdate:newLocation];
updateCount++;
}
else {
[self.delegate locationChange:newLocation :oldLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
[self.delegate locationError:error];
}
- (void)dealloc {
[self.locationManager release];
[super dealloc];
}
@end
- (void)locationUpdate:(CLLocation *)location;
- (void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation;
- (void)locationError:(NSError *)error;
locationController = [[MyCLController alloc] init];
locationController.delegate = self;
locationController.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationController.locationManager.distanceFilter = kCLDistanceFilterNone;
[locationController.locationManager startUpdatingLocation];
- (void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation {//
NSTimeInterval difference = [[newLocation timestamp] timeIntervalSinceDate:[oldLocation timestamp]];
double temp_distance = [newLocation getDistanceFrom:oldLocation];
distance += temp_distance;
distanceLbl.text = [NSString stringWithFormat:@\"%.2f\",distance];
currentSpeed = (temp_distance/difference) * (18.0/5.0);
if (currentSpeed > maxSpeed) {
maxSpeed = currentSpeed;
maxSpeedLbl.text = [NSString stringWithFormat:@\"%.2f\",maxSpeed];
}
currentSpeedLbl.text = [NSString stringWithFormat:@\"%.2f\",currentSpeed];
}
-(void)locationUpdate:(CLLocation *)location {
NSLog(@\"locationUpdate\");
}
- (void)locationError:(NSError *)error {
NSLog(@\"locationError\");
}
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeYou probably should be filtering-out values with high values for horizontal accuracy. (I wish they wouldn't call it that - it's horizontal INaccuracy!) Be careful if you do that to keep track of the last location on your own, rather than using the one supplied in the callback. (i.e. you will be filtering out some locations, so you have to compute distance/speed from the last GOOD location).
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI don't use the CLLocation speed property.
Today I will be jogging so I will change my application, so it will log longtitudes and latitudes, timestamps, speeds (using my method and cllocation property) and the horizontalAccuracy into textView and I will study the result. If I figure anything out, I will post it here.
Maybe anybody know the solution? If since 3.0 developers can make turn by turn navigation I guess, knowing the right speed will be very important :).
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeWhat is the distance filter you are using? This can still be a problem, as you won't necessarily get an update when you are standing still, and so you will see an erroneous speed.
As well, you aren't doing any filtering-out of inaccurate readings.
You may want to consider writing your data to the log or even to a file. I have a debug option to write all my data to a GPX file, which I can upload to my computer later. (You don't need to write any software to do the upload. You can get the log or the file using Organizer.)
With the GPX file, you can view your path on Google Earth, and really see what is going on with your data.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI don't know how rest of the users will use my app, but I use it for jogging, not fliying, driving, but jogging.
Do you have any idea what CLLocations with what value of horizontall accuracy should I be ignoring?
if (newLocation.horizontalAccuracy > 10) {
//sth
}
is ten metres good? of course I'm talking about GPS in 3G, not any location services by wifi or cell towers in 2g/touch 1g.
Best regards
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI have the same Problem....I´m trying to get accurat speeds since weeks and it will not function very well. Is here anyone who can provide a code sample were the speed is just as accurat as in the App RunKeeper? For higher speeds, it´s easy, but for Jogging and cycling I can´t get good and accurat speeds. It´s exasperating :'(
thx
dragi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIf you "know" that the user is walking versus driving, then you can use that information to filter out bad/erroneous readings.
Location readings (via GPS) are not 100% accurate. An error of 10 feet throws off calculations by a wide margin when somebody is a pedestrian. If you are in a car, 10 feet is not much compared to the distance traveled.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome