【问题标题】:Extract image location data提取图像位置数据
【发布时间】:2014-01-21 10:43:25
【问题描述】:

我有一个应用程序,用户可以在其中拍照或从他们的相机胶卷中选择一张。我需要能够从拍摄图像的位置提取位置(纬度和经度)。目前我正在使用位置管理器来获取设备的位置,但这可能会导致位置不准确(即有人可能会拍照但直到他们回家后才通过电子邮件发送,从而改变了位置)

我在这里找到了一个使用“资产库”的解决方案,但是当我从相机胶卷中选择照片时出现 SIGBRAT 错误。

谁能告诉我我的代码哪里出错了,或者建议一种简单的方法来获取照片的拍摄位置。

以下是我的代码:

- (IBAction)takePhoto
{
    picker1 = [[UIImagePickerController alloc] init];
    picker1.delegate = self;
    [picker1 setSourceType: UIImagePickerControllerSourceTypeCamera];
    [self presentViewController:picker1 animated:YES completion:NULL];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager startUpdatingLocation];


}

- (IBAction)chooseExisting
{
    picker2 = [[UIImagePickerController alloc] init];
    picker2.delegate = self;
    [picker2 setSourceType: UIImagePickerControllerSourceTypePhotoLibrary];
    [self presentViewController:picker2 animated:YES completion:NULL];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager startUpdatingLocation];



}


#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    if (currentLocation != nil) {
        longditute = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        Latitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
    }
    // Stop Location Manager
    [locationManager stopUpdatingLocation];
}



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

   image = [info objectForKey:UIImagePickerControllerOriginalImage];
   [imageView setImage:image];
   [self dismissViewControllerAnimated:YES completion:NULL];

    assetsLibrary = [[ALAssetsLibrary alloc] init];
    groups = [NSMutableArray array];

    [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos  usingBlock:^(ALAssetsGroup *group, BOOL *stop)
    {
        if (group == nil)
        {
            return;
        }

        [groups addObject:group];

    } failureBlock:^(NSError *error)
    {
        // Possibly, Location Services are disabled for your application or system-wide. You should notify user to turn Location Services on. With Location Services disabled you can't access media library for security reasons.

    }];
    ALAssetsGroup *group = [groups objectAtIndex:0];
    [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
     {
         if (result == nil)
         {
             return;
         }

         // Trying to retreive location data from image
         CLLocation *loc = [result valueForProperty:ALAssetPropertyLocation];
         NSLog(loc);
     }];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}

【问题讨论】:

  • 您在哪一行收到SIGABRT?日志说什么?堆栈跟踪说明了什么?

标签: ios objective-c ios7 xcode5


【解决方案1】:

您说,或者您能否展示一种获取数据的简单方法。

所以我可以为您指出两个处理这个确切问题的帖子。您首先需要确保用户已授予应用权限以允许位置服务获取应用所需的详细信息。

Nice answer given over here涵盖了解决的问题,包括代码和另一个很好的答案given here更详细 先检查第一个,然后检查第二个链接。

【讨论】:

  • 以下行出现声明错误:CGImageDestinationRef dr = CGImageDestinationCreateWithURL ((__bridge CFURLRef)fileURL,
  • 我不知道,最好对在我给你的链接中发布答案的人发表评论。我回答的目的是把你推向我所做的正确方向。
猜你喜欢
  • 2017-09-27
  • 1970-01-01
  • 2019-12-08
  • 2020-03-03
  • 2019-10-08
  • 1970-01-01
  • 2020-03-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多