9

Is it possible, in an iPhone app, to extract location information (geocode, I suppose it's called) from a photo taken with the iPhone camera?

If there is no API call to do it, is there any known way to parse the bytes of data to extract the information? Something I can roll on my own?

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
bpapa
  • 21,409
  • 25
  • 99
  • 147

2 Answers2

6

Unfortunately no.

The problem is thus;

A jpeg file consists of several parts. For this question the ones we are interested in are the image data and the exif data. The image data is the picture and the exif data are where things like geocoding, shutter speed, camera type and so on are stored.

A UIImage (and CGImage) only contain image data, no tags.

When the image picker selects an image (either from the library or the camera) it returns a UIImage, not a jpeg. This UIImage is created from the jpeg image data, but the exif data in the jpeg is discarded.

This means this data is not in the UIImage at all and thus is not accessible.

Andrew Grant
  • 58,260
  • 22
  • 130
  • 143
  • Is there any known way to parse the bytes of data to extract the information? Perhaps not an API call, but something I can roll on my own? – bpapa Mar 05 '09 at 20:01
  • Afraid not, I've clarified the answer to explain why. – Andrew Grant Mar 05 '09 at 20:17
  • This isn't strictly true. It's possible, as some apps (such as Mobile Photos and PixelPipe) seem to be able to manage it. I still haven't found any sample code though. – tomtaylor Jul 06 '09 at 18:36
2

I think the selected answer is wrong, actually. Well, not wrong. Everything it said is correct, but there is a way around that limitation.

UIImagePickerController passes a dictionary along with the UIImage it returns. One of the keys is UIImagePickerControllerMediaURL which is "the filesystem URL for the movie". However, as noted here in newer iOS versions it returns a url for images as well. Couple that with the exif library mentioned by @Jasper and you might be able to pull geotags out of photos.

I haven't tried this method, but as @tomtaylor mentioned, this has to be possible somehow, as there are a few apps that do it. (e.g. Lab).

Community
  • 1
  • 1
Kenny Winker
  • 11,919
  • 7
  • 56
  • 78
  • When i tried this (iOS 4.2) it does not return that key - just UIImagePickerControllerMediaType, UIImagePickerControllerOriginalImage and UIImagePickerControllerReferenceURL, which was `"assets-library://asset/asset.jpg?id=2317&ext=jpg"` – Alex Brown Dec 14 '10 at 22:06
  • Good to know... Maybe it was just there in 3.2? – Kenny Winker Dec 15 '10 at 00:27
  • I can confirm that picking a photo from the Saved Photos Album only gives you back the three keys Alex mentioned. When picking from the camera, as the OP was interested in, you get neither UIImagePickerControllerMediaURL nor UIImagePickerControllerReferenceURL. – dvs Aug 26 '11 at 20:14