开发者

Time interval between location updates, iphone

I have a CLLocation Manager called "myLocation"

myLocation = [[CLLocationManager alloc] init];
    myLocation.desiredAccuracy = kCLLocationAccuracyBestForNavigation ;
        myLocation.delegate=self;
[myLocation startUpdatingLocation];

I need to know time interval between location updates. I am using timestamp to find when new location was found as follows in didUpdateToLocation method

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
NSTimeInterval locationAge = abs([oldLocation.timestamp timeIntervalSinceNow]);

    NSString *timei开发者_运维技巧nNSString = [NSString stringWithFormat:@"%f", locationAge];

    NSLog(@"Location Age is %@", timeinNSString);
}

But NSlog always prints 0. any Idea what I am missing here? Thanks for any help in advance.


abs() doesn't work with floating point numbers. Use fabs() instead. In the future, use breakpoints and step through your code in the debugger to check where it actually fails.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜