iosobjective-cuiimagepickercontrollergeotagging

Get location in metadata of image when source type is Camera in UIImagePickerController ( kind of geotagging )


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!


Solution

  • 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.