在iOS中拍摄图像时如何显示纬度和经度

在iOS中拍摄图像时如何显示纬度和经度,ios,cocoa-touch,Ios,Cocoa Touch,每当我拍照时,我只需要图像的经度和纬度,我不想保存图像,我只需要图像的经度和纬度 如何在每次拍摄图像时获得图像的经度和纬度,这里我使用的是用于相机的ui图像选择器控制器 - (IBAction)btnCameraAction:(id)sender { UIImagePickerController *imagePickController=[[UIImagePickerController alloc]init]; imagePickController.sourceType=UIImagePi

每当我拍照时,我只需要图像的经度和纬度,我不想保存图像,我只需要图像的经度和纬度

如何在每次拍摄图像时获得图像的经度和纬度,这里我使用的是用于相机的ui图像选择器控制器

- (IBAction)btnCameraAction:(id)sender
{
UIImagePickerController *imagePickController=[[UIImagePickerController alloc]init];
imagePickController.sourceType=UIImagePickerControllerSourceTypeCamera;
imagePickController.delegate=self;
imagePickController.allowsEditing=TRUE;
[self presentViewController:imagePickController animated:YES completion:nil];
}

非常感谢任何代码帮助。提前感谢。

您真的应该使用
AlassetLibrary
。它更舒适:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {

    NSURL *url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
    self.imgInf = info;

    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myass)
    {
        CLLocation *location = [myass valueForProperty:ALAssetPropertyLocation];
        UIImage *image = [self.imgInf objectForKey:UIImagePickerControllerOriginalImage];
    };

    ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *err)
    {
        NSLog(@"Error: %@",[err localizedDescription]);
    };

    ALAssetsLibrary* al = [[ALAssetsLibrary alloc] init];
    [al assetForURL:url resultBlock:resultblock failureBlock:failureblock];
}

[picker dismissModalViewControllerAnimated:YES]; }
您可以通过其他标志获取有关图像的不同信息:


ALAssetPropertyType
阿拉塞特属性定位
阿拉塞特酒店
AlassetProperty方向
阿拉塞特酯
ALAssetPropertyRepresentations
ALAssetPropertyURLs

编辑:
我更改了源类型以满足您的要求。

图像没有任何纬度和经度

你可以用下面的方法来做

您可以在捕获图像时通过应用程序检查并保存当前位置

//To get user location
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
    [locationManager startUpdatingLocation];
    CLLocation *location = [locationManager location];
    CLLocationCoordinate2D coordinate = [location coordinate];
    getCurrentLatitude = coordinate.latitude;
    getCurrentLongitude = coordinate.longitude;
并将图像与任何本地资源一起保存,后者在您需要时可以使用

您还可以通过CLGeoCoder提取地址


或者你可以看看这个问题:

当调用camera delegate didfinishpickingimage时,获取图像并访问其属性大小,这将为你提供图像的高度和宽度当我在日志中发布时,url将为空。我不想要UIImagePickerController源类型PhotoLibrary,我只想要立即更新纬度经度,我不会把这张照片储存在我的画廊里。我误解了你的问题。您可以使用UIImagePickerController的委托,具体使用我上面描述的didFinishPickingMediaWithInfo方法。您将需要ALAssetsLibrary来访问NSDictionary,它将包含您要查找的数据。我的位置为零,我做错了什么。什么是图像没有纬度和经度?进出口银行的数据清楚地表明了这一点。还有,我同意,你的方法实际上是可行的。