Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

read iOS photo stream, don't show 0,0 coodinates on map

commit 2bbd0155dbecb94abcdddaf7ee86d17b2fa16600 1 parent 63e7a92
@nst authored
View
1  Classes/SPImageAnnotation.h
@@ -24,5 +24,6 @@
+ (SPImageAnnotation *) annotationWithCoordinate:(CLLocationCoordinate2D)coord date:(NSDate *)date path:(NSString *)path;
- (NSString *)annotationViewIdentifier;
+- (BOOL)hasValidCoordinates;
@end
View
5 Classes/SPImageAnnotation.m
@@ -16,7 +16,12 @@ @implementation SPImageAnnotation
@synthesize path;
@synthesize coordinate;
+- (BOOL)hasValidCoordinates {
+ return coordinate.longitude != 0.0 && coordinate.latitude != 0.0;
+}
+
+ (SPImageAnnotation *)annotationWithCoordinate:(CLLocationCoordinate2D)coord date:(NSDate *)date path:(NSString *)path {
+
SPImageAnnotation *annotation = [[SPImageAnnotation alloc] init];
annotation.coordinate = coord;
annotation.path = path;
View
3  Classes/SPSourceLocationTVC.m
@@ -27,7 +27,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
SPImageMapVC *mapVC = [[SPImageMapVC alloc] initWithNibName:@"SPImageMapVC" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:mapVC animated:YES];
SPImageAnnotation *annotation = [SPImageAnnotation annotationWithCoordinate:cachedLocationFromMaps.coordinate date:nil path:nil];
- [mapVC addAnnotation:annotation];
+ if(annotation)
+ [mapVC addAnnotation:annotation];
}
}
View
70 Classes/SPSourcePhotosTVC.m
@@ -22,35 +22,38 @@ @implementation SPSourcePhotosTVC
@synthesize imageVC;
- (void)mapButtonClicked:(id)sender {
- mapVC.annotations = annotations;
- [self.navigationController pushViewController:mapVC animated:YES];
+ NSArray *annotationsWithValidCoordinates = [annotations filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
+ SPImageAnnotation *annotation = (SPImageAnnotation *)evaluatedObject;
+ return [annotation hasValidCoordinates];
+ }] ];
+
+ mapVC.annotations = annotationsWithValidCoordinates;
+
+ [self.navigationController pushViewController:mapVC animated:YES];
}
-- (NSArray *)jpgPaths {
+- (NSArray *)jpgPngPaths {
NSMutableArray *a = [NSMutableArray array];
-
- NSString *path = @"/var/mobile/Media/PhotoData/100APPLE";
-// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
-// NSString *documentsDirectory = [paths count] ? [paths objectAtIndex:0] : nil;
-// NSString *path = [documentsDirectory stringByAppendingPathComponent:@"../../../Media/DCIM"];
-// path = [path stringByStandardizingPath];
-
- NSDirectoryEnumerator *dirEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:path];
-
- BOOL isDir;
-
- BOOL exists;
- NSString *filePath = nil;
-
- NSString *dirContent = nil;
- while(dirContent = [dirEnumerator nextObject]) {
- filePath = [path stringByAppendingPathComponent:dirContent];
- exists = [[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDir];
- if(exists && !isDir && [[filePath pathExtension] isEqualToString:@"THM"]) {
- [a addObject:filePath];
- }
- }
-
+
+ NSString *dirPath = @"/private/var/mobile/Media/PhotoStreamsData/";
+ NSFileManager *fm = [[NSFileManager alloc] init];
+ NSDirectoryEnumerator *dirEnum = [fm enumeratorAtPath:dirPath];
+
+ NSString *path = nil;
+ while (path = [dirEnum nextObject]) {
+
+ if([[path pathComponents] containsObject:@".MISC"]) continue;
+
+ NSString *fullPath = [dirPath stringByAppendingPathComponent:path];
+
+ if([fm isReadableFileAtPath:fullPath] == NO) continue;
+
+ NSString *ext = [fullPath pathExtension];
+ if([ext isEqualToString:@"JPG"] || [ext isEqualToString:@"PNG"]) {
+ [a addObject:fullPath];
+ }
+ }
+
return a;
}
@@ -58,7 +61,9 @@ - (void)readPhotosInNewThread {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSEnumerator *e = [[self jpgPaths] reverseObjectEnumerator];
+ NSArray *jpgPngPaths = [self jpgPngPaths];
+
+ NSEnumerator *e = [jpgPngPaths reverseObjectEnumerator];
NSAutoreleasePool *subpool = [[NSAutoreleasePool alloc] init];
@@ -76,7 +81,6 @@ - (void)readPhotosInNewThread {
NSString *coordString = (lat && lon) ? [NSString stringWithFormat:@"%@, %@", lat, lon] : nil;
-
NSError *error = nil;
NSDictionary *d = [[NSFileManager defaultManager] attributesOfItemAtPath:s error:&error];
if(!d) {
@@ -85,16 +89,18 @@ - (void)readPhotosInNewThread {
}
NSDate *date = [d fileModificationDate];
NSString *dateString = date ? [date description] : @"";
-
+
SPImageAnnotation *annotation = [SPImageAnnotation annotationWithCoordinate:coord date:date path:s];
- [annotations performSelectorOnMainThread:@selector(addObject:) withObject:annotation waitUntilDone:YES];
-
+ [annotations performSelectorOnMainThread:@selector(addObject:) withObject:annotation waitUntilDone:YES];
+
NSDictionary *cd = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:coordString] forKey:dateString];
[contentsDictionaries performSelectorOnMainThread:@selector(addObject:) withObject:cd waitUntilDone:YES];
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
- [mapVC performSelectorOnMainThread:@selector(addAnnotation:) withObject:annotation waitUntilDone:YES];
+ if([annotation hasValidCoordinates]) {
+ [mapVC performSelectorOnMainThread:@selector(addAnnotation:) withObject:annotation waitUntilDone:YES];
+ }
}
[subpool release];
View
4 Classes/UIImage+GPS.m
@@ -15,7 +15,7 @@ @implementation UIImage (GPS)
// adapted from http://davidjhinson.wordpress.com/2009/06/05/you-can-have-it-in-any-color-as-long-as-its-black/
+(CLLocationCoordinate2D)coordinatesOfImageAtPath:(NSString *)path {
CLLocationCoordinate2D coord = {0.0, 0.0};
-
+
NSData *data =[NSData dataWithContentsOfFile:path];
if(!data) return coord;
@@ -26,7 +26,7 @@ +(CLLocationCoordinate2D)coordinatesOfImageAtPath:(NSString *)path {
EXFGPSLoc *lon = [jpegScanner.exifMetaData tagValue:[NSNumber numberWithInt:EXIF_GPSLongitude]];
NSString *lonRef = [jpegScanner.exifMetaData tagValue:[NSNumber numberWithInt:EXIF_GPSLongitudeRef]];
[jpegScanner release];
-
+
if([latRef length] == 0 || [lonRef length] == 0) return coord;
coord.latitude = [[NSString stringWithFormat:@"%f", lat.degrees.numerator + ((float)lat.minutes.numerator / (float)lat.minutes.denominator) / 60.0] floatValue];
View
8 SpyPhone.xcodeproj/project.pbxproj
@@ -684,11 +684,13 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
+ PROVISIONING_PROFILE = "";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SDKROOT = iphoneos;
};
@@ -698,12 +700,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Nicolas Seriot (9V2U949PMC)";
+ CODE_SIGN_IDENTITY = "iPhone Developer";
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- "PROVISIONING_PROFILE[sdk=iphoneos*]" = "32101231-1E4B-460A-8AF0-A5BD41F1D898";
+ PROVISIONING_PROFILE = "";
+ "PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SDKROOT = iphoneos;
};
name = Release;
View
BIN  SpyPhone.xcodeproj/project.xcworkspace/xcuserdata/nst.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.