如何从相机拍摄的照片中获取纬度,经度或地址

时间:2015-06-12 05:46:45

标签: ios objective-c

我想从相机拍摄的照片中获取纬度,经度或地址,我使用了链接iPhone Get UIImagePickerController Lat/Lng

我使用的代码是

所以这就是我们处理选择器提供的信息的方式:

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

    if ([picker sourceType] == UIImagePickerControllerSourceTypePhotoCamera) {
        // We'll store the info to use in another function later
        self.imageInfo = 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)
        {
            // Get the location property from the asset  
            CLLocation *location = [myasset valueForProperty:ALAssetPropertyLocation];
            // I found that the easiest way is to send the location to another method
            [self handleImageLocation:location];
        };
        // This block will handle errors:
        ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
        {
            NSLog(@"Can not get asset - %@",[myerror localizedDescription]);
            // Do something to handle the error
        };


        // Use the url to get the asset from ALAssetsLibrary,
        // the blocks that we just created will handle results
        ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
        [assetslibrary assetForURL:url 
                       resultBlock:resultblock
                      failureBlock:failureblock];

    }
}

但是位置变量返回nil。如何从相机拍摄的照片中提取位置或地址。

1 个答案:

答案 0 :(得分:1)

我已经使用下面的代码从相机图片中找到位置。希望这可以帮助你

$(document).ready(function(){
        $('#cart').on('change', function() {
          $('.coffee, .tea').hide();
          switch (this.value) {
            case "1":
              $('.coffee').show();
              break;
            case "2":
              $('.tea').show();
              break;
          }
        });
    });