【问题标题】:how to show latitude and longitude when i capture a image in iOS在iOS中捕获图像时如何显示纬度和经度
【发布时间】:2015-01-27 12:23:49
【问题描述】:

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

每当我捕获图像时如何获取图像的经度和纬度,这里我使用的是用于相机的 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];
}

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

【问题讨论】:

  • 当相机委托 didfinishpickingimage 被调用然后获取图像并访问它的属性大小,这将为您提供图像的高度和宽度

标签: ios cocoa-touch


【解决方案1】:

图片没有经纬度。

您可以通过以下方式进行。

无论是通过你的应用程序,当你捕捉图像时,你都可以通过

查看并保存当前位置
//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 提取地址

或者你可以看看这个 SO 问题:Hot to get current location at the instant UIImagePickerController captures an image

【讨论】:

  • 图片没有经纬度是什么意思? EXIF数据显然有它。附言不过,我同意,您的方法实际上是可用的。
【解决方案2】:

你真的应该使用ALAssetsLibrary。舒服多了:

- (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 ALAssetPropertyLocation ALAssetPropertyDuration ALAssetPropertyOrientation ALAssetPropertyDate ALAssetPropertyRepresentations ALAssetPropertyURLs

编辑: 我更改了 sourceType,使其符合您的要求。

【讨论】:

  • 这里的 url 当我在日志中发布时它会变为空。
  • 我不想要 UIImagePickerControllerSourceTypePhotoLibrary 我只想立即更新纬度和经度,我不会将该图像存储到我的画廊。
  • 我误解了你的问题。您可以使用 UIImagePickerController 的委托 - 具体的方法是我上面描述的 didFinishPickingMediaWithInfo。您需要 ALAssetsLibrary 来访问 NSDictionary,其中包含您要查找的数据。
  • 我的位置信息为零,我做错了什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多