testtestHome

Extracting GPS data from a photo's EXIF-data using PHP…

01.02.2009 by Mich - lire la version francophone (2) - lees dit in het Nederlands

I recently bought a new mobile phone, the Nokia N79, successor of my old N73. The N79 has a GPS-chip and a camera, which means geotagging fun !

The N79 stores GPS-data in the EXIF-information of the photo. By default, this is disabled. You'll have to turn it on in the settings of the camera:

Once activated, GPS-coordinates will be stored in the EXIF-headers. You can read those using the following code:

Reading EXIF data:
$exif = exif_read_data('dummyimage.jpg',0,TRUE);

Degrees:
$deg=$exif["GPS"]["GPSLatitude"][0];

Minutes:
$min=$exif["GPS"]["GPSLatitude"][1];

Seconds:
$sec=$exif["GPS"]["GPSLatitude"][2];

Hemisphere (N, S, W ou E):
$hem=$exif["GPS"]["GPSLatitudeRef"];

Altitude:
$alt=$exif["GPS"]["GPSAltitude"][0];

(for longitude, replace "GPSLatitude" by "GPSLongitude" in the above code)

I'm using this code to grab GPS data out of pictures so I can geotag blog-entries posted from my mobile.

tags: . . .

Add a comment