Table of Contents

GPS

PHP Code

public function getGps($exifCoord, $hemi) {
 
    $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
    $minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
    $seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
 
    $flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
 
    return $flip * ($degrees + $minutes / 60 + $seconds / 3600);
 
}
 
public function gps2Num($coordPart) {
 
    $parts = explode('/', $coordPart);
 
    if (count($parts) <= 0)
        return 0;
 
    if (count($parts) == 1)
        return $parts[0];
 
    return floatval($parts[0]) / floatval($parts[1]);
}
// Sample Usage
$exif = exif_read_data($filename, 'GPS', true, false);
$lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
$lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
var_dump($lat, lon);
 
float(-33.8751666667)
float(151.207166667)

Exif (Exchangeable Image File Format)

The Japan Electronic Industries Development Association published Version 2.1 of the specification in June 1998 with an initial specification release in 1995. Yes, that is correct. The 1998 version is 2.1, which is what many hardware manufacturers are (somewhat) implementing today in devices such as cameras, scanners, and smartphones!

Now, the Exif metadata is stored in the APP1 marker of JPG files, so if you are looking at the picture in a hex/text editor, you can search for segment marker 0xFFE1.

Tips

Warnings

References