Created
July 13, 2012 13:21
-
-
Save odrobnik/3104860 to your computer and use it in GitHub Desktop.
Code where the crash occurred
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)recordLocation:(CLLocation *)location | |
{ | |
if (previousRecordedLocation) | |
{ | |
NSTimeInterval interval = [location.timestamp timeIntervalSinceDate:previousRecordedLocation.timestamp]; | |
NSTimeInterval distance = [location distanceFromLocation:previousRecordedLocation]; | |
CLLocationDistance currentSpeed = distance/interval; | |
if (previousRecordedSpeed) | |
{ | |
CLLocationDistance speedDelta = (currentSpeed - previousRecordedSpeed)/interval; | |
if (fabs(speedDelta)>=4.0 || currentSpeed > 120) | |
{ | |
// ignoring implausible speed change | |
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FilterSignalDips"]) | |
{ | |
return; | |
} | |
} | |
} | |
previousRecordedSpeed = currentSpeed; | |
} | |
[previousRecordedLocation release]; | |
previousRecordedLocation = [location retain]; | |
// make new trackpoint | |
TrackPoint *newTrackPoint = (id)[NSEntityDescription insertNewObjectForEntityForName:@"TrackPoint" inManagedObjectContext:self.managedObjectContext]; | |
newTrackPoint.latitude = [NSNumber numberWithDouble:location.coordinate.latitude]; | |
newTrackPoint.longitude = [NSNumber numberWithDouble:location.coordinate.longitude]; | |
newTrackPoint.horizontalAccuracy = [NSNumber numberWithDouble:location.horizontalAccuracy]; | |
newTrackPoint.timestamp = location.timestamp; | |
if (location.verticalAccuracy>0) | |
{ | |
newTrackPoint.altitude = [NSNumber numberWithDouble:location.altitude]; | |
newTrackPoint.verticalAccuracy = [NSNumber numberWithDouble:location.verticalAccuracy]; | |
} | |
if (!trackCurrentlyRecording) | |
{ | |
// make new track | |
Track *newTrack = (id)[NSEntityDescription insertNewObjectForEntityForName:@"Track" inManagedObjectContext:self.managedObjectContext]; | |
newTrack.name = [self.dateTitleFormatter stringFromDate:location.timestamp]; | |
newTrack.distance = [NSNumber numberWithDouble:0]; | |
newTrack.beginTimestamp = location.timestamp; | |
self.trackCurrentlyRecording = newTrack; | |
} | |
// add to current recording track | |
[trackCurrentlyRecording addTrackPointsObject:newTrackPoint]; | |
if (trackCurrentlyRecording.mostRecentTrackPoint) | |
{ | |
CLLocationDistance currentDistance = [trackCurrentlyRecording.distance doubleValue]; | |
CLLocationDistance addedDistance = [[trackCurrentlyRecording.mostRecentTrackPoint location] distanceFromLocation:location]; | |
currentDistance += addedDistance; | |
trackCurrentlyRecording.distance = [NSNumber numberWithDouble:currentDistance]; | |
} | |
trackCurrentlyRecording.mostRecentTrackPoint = newTrackPoint; | |
[[NSNotificationCenter defaultCenter] postNotificationName:@"RecordedTrackPoint" object:newTrackPoint userInfo:nil]; | |
NSError *error; | |
if (![self.managedObjectContext save:&error]) | |
{ | |
NSLog(@"Error saving MOC: %@", [error localizedDescription]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment