Skip to content
Browse files

got useful json from the device

  • Loading branch information...
1 parent 135cc09 commit 2102f2f805eb8e58ed3fdd467046b72403dc73c6 @jchris jchris committed May 13, 2011
Showing with 38 additions and 19 deletions.
  1. +38 −19 OnTheSpot/RootViewController.m
View
57 OnTheSpot/RootViewController.m
@@ -161,7 +161,7 @@ - (void)tableView:(UITableView *)tableView
NSError* error = NULL;
NSData* theJSON = [[CJSONSerializer serializer] serializeDictionary:jsonData error:&error];
if (error != NULL) {
- NSLog(@"Error while serializing %@", jsonData);
+ NSLog(@"Error while serializing for view %@", jsonData);
detailViewController.textView.text = [jsonData description];
}
else {
@@ -233,9 +233,16 @@ - (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
- NSMutableDictionary* sample = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- [NSDate date], @"timestamp"
- , newLocation, @"location"
+ NSMutableDictionary* sample =
+ [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ [NSDate date], @"timestamp"
+ , [NSNumber numberWithDouble:newLocation.coordinate.latitude], @"lat"
+ , [NSNumber numberWithDouble:newLocation.coordinate.longitude], @"lon"
+ , [NSNumber numberWithDouble:newLocation.altitude], @"altitude"
+ , [NSNumber numberWithDouble:newLocation.course], @"course"
+ , [NSNumber numberWithDouble:newLocation.speed], @"speed"
+ , [NSNumber numberWithDouble:newLocation.horizontalAccuracy], @"horizontalAccuracy"
+ , [NSNumber numberWithDouble:newLocation.verticalAccuracy], @"verticalAccuracy`"
, nil];
[_locationSamples addObject:sample];
@@ -244,10 +251,13 @@ - (void)locationManager:(CLLocationManager *)manager
- (void)locationManager:(CLLocationManager *)manager
didUpdateHeading:(CLHeading *)newHeading
{
- NSMutableDictionary* sample = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- [NSDate date], @"timestamp"
- , newHeading, @"heading"
- , nil];
+ NSMutableDictionary* sample =
+ [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ [NSDate date], @"timestamp"
+ , [NSNumber numberWithDouble:newHeading.magneticHeading], @"magneticHeading"
+ , [NSNumber numberWithDouble:newHeading.trueHeading], @"trueHeading"
+ , [NSNumber numberWithDouble:newHeading.headingAccuracy], @"headingAccuracy"
+ , nil];
[_headingSamples addObject:sample];
}
@@ -271,6 +281,7 @@ - (void)storeImage:(UIImage*)anImage withMetaData:(NSDictionary*)metaData
// may not have been taken at the exact same time as the picture.
NSDate* sampleTimestamp = [sample valueForKey:@"timestamp"];
if ([dateTimeDigitized timeIntervalSinceDate:sampleTimestamp] <= 0.0) {
+ [sample removeObjectForKey:@"timestamp"];
motionData = sample;
break;
}
@@ -281,15 +292,17 @@ - (void)storeImage:(UIImage*)anImage withMetaData:(NSDictionary*)metaData
for (NSDictionary* sample in _locationSamples) {
NSDate* sampleTimestamp = [sample valueForKey:@"timestamp"];
if ([dateTimeDigitized timeIntervalSinceDate:sampleTimestamp] <= 0.0) {
+ [sample removeObjectForKey:@"timestamp"];
locationData = sample;
break;
}
}
- NSDictionary* headingData = nil;
- for (NSDictionary* sample in _headingSamples) {
+ NSMutableDictionary* headingData = nil;
+ for (NSMutableDictionary* sample in _headingSamples) {
NSDate* sampleTimestamp = [sample valueForKey:@"timestamp"];
if ([dateTimeDigitized timeIntervalSinceDate:sampleTimestamp] <= 0.0) {
+ [sample removeObjectForKey:@"timestamp"];
headingData = sample;
break;
}
@@ -299,8 +312,8 @@ - (void)storeImage:(UIImage*)anImage withMetaData:(NSDictionary*)metaData
// [dateFormatter ]
NSMutableDictionary* jsonData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- anImage, @"imageData" // will be stored as an attachment to the document in CouchDB
- , metaData, @"mediaMetaData"
+// anImage, @"imageData" // will be stored as an attachment to the document in CouchDB
+ metaData, @"mediaMetaData"
, motionData, @"motionData"
, locationData, @"locationData"
, headingData, @"headingData"
@@ -346,7 +359,6 @@ - (void)storeImage:(UIImage*)anImage withMetaData:(NSDictionary*)metaData
// [op start];
// }
}
-//>>>>>>> Stashed changes
}
- (void)startMotionSampling
@@ -419,12 +431,19 @@ - (void)stopMotionSampling
- (void)takeMotionSample:(NSTimer*)aTimer
{
- NSMutableDictionary* sample = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- [NSDate date], @"timestamp"
- , _motionManager.gyroData, @"gyroData"
- , _motionManager.deviceMotion, @"deviceMotion"
- , _motionManager.accelerometerData, @"accelerometerData"
- , nil];
+ NSMutableDictionary* sample =
+ [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ [NSDate date], @"timestamp"
+ , [NSNumber numberWithDouble:_motionManager.gyroData.rotationRate.x], @"gyro-x"
+ , [NSNumber numberWithDouble:_motionManager.gyroData.rotationRate.y], @"gyro-y"
+ , [NSNumber numberWithDouble:_motionManager.gyroData.rotationRate.z], @"gyro-z"
+ , [NSNumber numberWithDouble:_motionManager.deviceMotion.attitude.roll], @"attitude-roll"
+ , [NSNumber numberWithDouble:_motionManager.deviceMotion.attitude.pitch], @"attitude-pitch"
+ , [NSNumber numberWithDouble:_motionManager.deviceMotion.attitude.yaw], @"attitude-yaw"
+ , [NSNumber numberWithDouble:_motionManager.accelerometerData.acceleration.x], @"accel-x"
+ , [NSNumber numberWithDouble:_motionManager.accelerometerData.acceleration.y], @"accel-y"
+ , [NSNumber numberWithDouble:_motionManager.accelerometerData.acceleration.z], @"accel-z"
+ , nil];
[_motionSamples addObject:sample];
}

0 comments on commit 2102f2f

Please sign in to comment.
Something went wrong with that request. Please try again.