If you are using ImagePickerController and wants to get selected Image location then use below code:-
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    // Get the asset url
    NSURL *url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
    // We need to use blocks. This block will handle the ALAsset that's returned:
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
    {
        NSMutableDictionary *assetMetadata = [[[myasset defaultRepresentation] metadata] mutableCopy];
               // Get the location property from the asset
        CLLocation *assetLocation = [myasset valueForProperty:ALAssetPropertyLocation];
        NSDictionary *gpsData = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithDouble:[assetLocation coordinate].longitude], @"Longitude",     [NSNumber numberWithDouble:[assetLocation coordinate].latitude], @"Latitude", nil];
        [assetMetadata setObject:gpsData forKey:@"Location Information"];
    };
    // This block will handle errors:
    ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
    {
        NSLog(@"Can not get asset - %@",[myerror localizedDescription]);
        // Do something to handle the error
    };
    ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
    [assetslibrary assetForURL:url
                   resultBlock:resultblock
                  failureBlock:failureblock];
    // Use the url to get the asset from ALAssetsLibrary,
    // the blocks that we just created will handle results
}
                       
                    
0 Comment(s)