0

I am trying to get or capture user location within metadata of image picked by UIImagePickerController having source type set UIImagePickerControllerSourceTypeCamera.

When source type is camera(image clicked by camera), we can get metadata from the info parameter of didFinishPickingMediaWithInfo but it doesn't contain location information.

If source type is photolibrary (UIImagePickerControllerSourceTypePhotoLibrary) then we can get location in metadata with below code,

 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{


    NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
    PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
    PHAsset *asset = fetchResult.firstObject;

    NSLog(@"%f,%f",asset.location.coordinate.latitude,asset.location.coordinate.longitude);


[picker dismissViewControllerAnimated:YES completion:nil];

}

Second thing we can also manage location with CLLocationManager, I mean we can capture location in didFinishPickingMediaWithInfo. But I just want to know that is it possible to pick location with metadata in didFinishPickingMediaWithInfo when image is picked by camera or source type is camera ?

Any help will be appreciated. Thanks!

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • The metadata is in UIImagePickerControllerMediaMetadata. But it doesn't include location info; that's up to you. – matt Oct 23 '17 at 14:47
  • @matt : Yeah! Metadata is available in `UIImagePickerControllerMediaMetadata` and doesn't contains location information. Thanks for the suggestion. :) – Ketan Parmar Oct 24 '17 at 10:20
  • 1
    Right, think of it this way. You're authorized to use the camera already, so picking up camera metadata (what focal length, what kind of iPhone, etc.) is automatic. But authorization to get the user's location is a completely different ball game. That's not part of taking a photo; it's something _else_ that a photo-taking app _might_ do. The Camera app can do it if and only if the user has authorized it. Now _you_ are the app, so if you want location info, _you_ need authorization and _you_ need to gather and insert that info. – matt Oct 24 '17 at 14:45
  • @matt : Yeah Exactly! Location shouldn't be in metadata because it requires permission ! Totally agree with you. – Ketan Parmar Oct 25 '17 at 05:11

1 Answers1

1

I came to conclusion that if we take photo using Camera then we can not get location in metadata, so if we want to get location when image get captured from camera we have to use default location service (CLLocationManager) at a time of capturing - I mean in didFinishPickingMediaWithInfo method.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75