123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #import "CCExifGeo.h"
- @implementation CCExifGeo
- + (void)setExifLocalTableFileID:(CCMetadata *)metadata directoryUser:(NSString *)directoryUser activeAccount:(NSString *)activeAccount
- {
- NSString *stringLatitude;
- NSString *stringLongitude;
-
- NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]];
-
- CGImageSourceRef originalSource = CGImageSourceCreateWithURL((CFURLRef) url, NULL);
-
- NSDictionary *structExif =(__bridge NSDictionary*) CGImageSourceCopyPropertiesAtIndex(originalSource, 0, NULL);
-
- NSDictionary *tiff = [structExif objectForKey:@"{TIFF}"];
- NSString *dateTime = [tiff objectForKey:@"DateTime"];
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
-
- [dateFormatter setDateFormat:@"yyyy:MM:dd HH:mm:ss"];
-
- NSDate *date = [[NSDate alloc] init];
- date = [dateFormatter dateFromString:dateTime];
- if (!date) date = metadata.date;
-
- NSDictionary *gps = [structExif objectForKey:@"{GPS}"];
- double latitude = [[gps objectForKey:@"Latitude"] doubleValue];
- double longitude = [[gps objectForKey:@"Longitude"] doubleValue];
-
- NSString *latitudeRef = [gps objectForKey:@"LatitudeRef"];
- NSString *longitudeRef = [gps objectForKey:@"LongitudeRef"];
-
-
- if ([latitudeRef isEqualToString:@"N"])
- stringLatitude = [NSString stringWithFormat:@"+%.4f", latitude];
- else
- stringLatitude = [NSString stringWithFormat:@"-%.4f", latitude];
-
-
-
-
- if ([longitudeRef isEqualToString:@"E"])
- stringLongitude = [NSString stringWithFormat:@"+%.4f", longitude];
- else
- stringLongitude = [NSString stringWithFormat:@"-%.4f", longitude];
- if (latitude == 0 || longitude == 0){
-
- stringLatitude = @"0";
- stringLongitude = @"0";
- }
-
-
- [CCCoreData setGeoInformationLocalFromFileID:metadata.fileID exifDate:date exifLatitude:stringLatitude exifLongitude:stringLongitude activeAccount:activeAccount];
- }
- + (void)setGeocoderFileID:(NSString *)fileID exifDate:(NSDate *)exifDate latitude:(NSString*)latitude longitude:(NSString*)longitude
- {
-
- if ([CCCoreData getLocationFromGeoLatitude:latitude longitude:longitude]) return;
-
- CLGeocoder *geocoder = [[CLGeocoder alloc] init];
- CLLocation *location = [[CLLocation alloc] initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue]];
-
- [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
-
-
-
- if (error == nil && [placemarks count] > 0) {
-
- CLPlacemark *placemark = [placemarks lastObject];
-
- NSString *thoroughfare = @"";
- NSString *postalCode = @"";
- NSString *locality = @"";
- NSString *administrativeArea = @"";
- NSString *country = @"";
-
- if (placemark.thoroughfare) thoroughfare = placemark.thoroughfare;
- if (placemark.postalCode) postalCode = placemark.postalCode;
- if (placemark.locality) locality = placemark.locality;
- if (placemark.administrativeArea) administrativeArea = placemark.administrativeArea;
- if (placemark.country) country = placemark.country;
-
- NSString *location = [NSString stringWithFormat:@"%@ %@ %@ %@ %@", thoroughfare, postalCode, locality, administrativeArea, country];
- location = [location stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
-
-
- if ([location length] > 0) {
-
- [CCCoreData setGeocoderLocation:location placemarkAdministrativeArea:placemark.administrativeArea placemarkCountry:placemark.country placemarkLocality:placemark.locality placemarkPostalCode:placemark.postalCode placemarkThoroughfare:placemark.thoroughfare latitude:latitude longitude:longitude];
-
- NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:exifDate, fileID, nil];
-
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"insertGeocoderLocation" object:nil userInfo:dictionary];
- }
- } else {
-
- }
- }];
- }
- @end
|