-->

How to write/get latitude longitude with image in

2020-07-14 12:27发布

问题:

Currently I am saving and image with the following method in "saved photos album".

UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

Now I want to associate the current latitude and longitude with that image.

How can I do so ?

Can I do with its mediaInfo dictionary (metadata).

I am working in ios sdk 3.0 .

Please tell me How to get /set geo data with an image in UIImageViewPickerController

回答1:

AFAIK this is not supported in iOS 4.0 and lower.

As of iOS 4.1, you can use -[ALAssetsLibrary writeImageToSavedPhotosAlbum:metadata:completionBlock:] to save images with metadata (untested but I assume this should work). I do not know how to format the metadata dictionary, though.

You should try to read some existing images that contain geodata from the assets library to check how the dictionary must be formatted.



回答2:

I am afraid that there is no way for you to do using UIImageWriteToSavedPhotosAlbum.

However, you can use another method to save into iphone file system (but not in "saved photos album"). Then you save its metadata in another text file, going with the image path:

For PNG:

[UIImagePNGRepresentation(image) writeToFile: uniquePath atomically: YES];

For JPG:

[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];


回答3:

If you are getting the image from Camera, you should get the location from CLLocationManager. If you pick the image from library, you can read the location coordinates using ALAssertsLibrary:

iPhone Get UIImagePickerController Lat/Lng

After you have the location, you should be able to use exif library to save the data with the image.



回答4:

you cant get latitude and longitude from image what comes from uiimagepickercontroller. It seems apple striping exif tags (i guess for privacy reasons).