Reputation: 1606
I can get the location information from photo album on ios, but I would like to access image location (latitude and longitude) when I took a photo.
so this is image finished event
public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info)
{
//UIImagePickerController.ReferenceUrl
var originalImage = new NSString("UIImagePickerControllerOriginalImage");
var image = (UIImage)info[originalImage];
foreach (var item in info)
Console.WriteLine(item.Key + " " + item.Value);
image.SaveToPhotosAlbum(delegate(UIImage img, NSError err)
{
Console.WriteLine("Saved!");
});
_dp.DismissModalViewController(true);
OnImageChoosed(image);
}
}
and in info dictionary, i can see those properties
UIImagePickerControllerMediaMetadata {
DPIHeight = 72;
DPIWidth = 72;
Orientation = 6;
"{Exif}" = {
ApertureValue = "2.27500704749987";
BrightnessValue = "5.267792568433492";
ColorSpace = 1;
DateTimeDigitized = "2015:07:08 14:24:15";
DateTimeOriginal = "2015:07:08 14:24:15";
ExposureBiasValue = 0;
ExposureMode = 0;
ExposureProgram = 2;
ExposureTime = "0.008333333333333333";
FNumber = "2.2";
Flash = 24;
FocalLenIn35mmFilm = 29;
FocalLength = "4.15";
ISOSpeedRatings = (
40
);
LensMake = Apple;
LensModel = "iPhone 6 back camera 4.15mm f/2.2";
LensSpecification = (
"4.15",
"4.15",
"2.2",
"2.2"
);
MeteringMode = 5;
PixelXDimension = 3264;
PixelYDimension = 2448;
SceneType = 1;
SensingMethod = 2;
ShutterSpeedValue = "6.908853996279415";
SubjectArea = (
1631,
1223,
1795,
1077
);
SubsecTimeDigitized = 927;
SubsecTimeOriginal = 927;
WhiteBalance = 0;
};
"{MakerApple}" = {
1 = 2;
14 = 0;
2 = <af001d01 9001ed01 9e011f01 70001500 41000d00 0a001000 12000900 0e000e00 b5003201 ae01f701 9b010401 5b001400 47002300 11001500 15000800 0d000d00 c2005501 eb014402 c901d900 67002400 3d002400 0f000b00 08000900 0d000d00 f1009201 30028e02 ff01b200 51000e00 43000e00 0d000e00 0d000d00 0c000b00 2d02b302 f802e902 26029700 80005600 5e000e00 0b000a00 09000900 0a000900 88039703 87033503 3c028300 44001100 45001100 0c000d00 0d000d00 0d000a00 b903b103 97034703 44027700 3e001000 38001000 0d000d00 0e000d00 0d000a00 a4039f03 87031503 22026d00 38000b00 34001000 0d001000 12000b00 0b000900 7b036a03 1d039c02 e2016400 37000e00 32001100 0d000a00 0a000600 07000700 c0029a02 4e02fb01 79015b00 36000e00 31001200 0c000900 0a000700 0c000b00 8b017801 4b013501 01015500 34000a00 30000900 06000c00 0e000800 14001000 b9001a00 34008a00 bd005000 2f000c00 2f000c00 0c000b00 0d000500 07000700 60000e00 0c002400 8f004b00 2f000a00 2d000f00 0e000700 07000700 0b000a00 47000b00 0a000b00 3d003300 28000a00 2b000a00 06000a00 0e000700 12001000 29000a00 09000a00 25003b00 2a000e00 2a000c00 0b000e00 11000700 0a000c00 27000a00 08000a00 0f003f00 3f001b00 31000d00 0e000700 07000700 0a000800>;
3 = {
epoch = 0;
flags = 1;
timescale = 1000000000;
value = 401611073225666;
};
4 = 1;
5 = 128;
6 = 119;
7 = 1;
8 = (
"0.01929908",
"-0.713904",
"-0.7083461"
);
};
"{TIFF}" = {
DateTime = "2015:07:08 14:24:15";
Make = Apple;
Model = "iPhone 6";
Software = "8.3";
XResolution = 72;
YResolution = 72;
};
As you see there is no location information. Well I tried to save image on local after get the location informatin but didnt work.
As I understand, If I can get path of the image which saved to the photo album, I can got
var path = args.Info[UIImagePickerController.ReferenceUrl].ToString();
refeenceURL like above and after I can get the location.. But i dont know how to get path of the newly saved image.
P.S.: I used Xamarin.iOS with C# but doesnt matter if you provide objective C or swift code.
Upvotes: 0
Views: 278
Reputation: 26385
I have an old snippet that I've never used (its an NSMutableDictionary
category), because in the app I've used AVFoundation, but it worth a try. Credits to the creator of that code Gustavo Ambrozio.
Since is really old you should adapt for ARC compatibility.
- (id)initWithInfoFromImagePicker:(NSDictionary *)info {
if ((self = [self init])) {
// Key UIImagePickerControllerReferenceURL only exists in iOS 4.1
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.1f) {
NSURL* assetURL = nil;
if ((assetURL = [info objectForKey:UIImagePickerControllerReferenceURL])) {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
NSDictionary *metadata = asset.defaultRepresentation.metadata;
[self addEntriesFromDictionary:metadata];
}
failureBlock:^(NSError *error) {
}];
[library autorelease];
}
else {
NSDictionary *metadata = [info objectForKey:UIImagePickerControllerMediaMetadata];
if (metadata)
[self addEntriesFromDictionary:metadata];
}
}
}
return self;
}
Upvotes: 1