Import GPS coordinates from EXIF

This commit is contained in:
Quentin Ligier 2016-04-17 21:59:50 +02:00
parent 20e22d2777
commit e2509b1657
2 changed files with 33 additions and 2 deletions

View File

@ -819,8 +819,11 @@ final class Photo {
if (!empty($exif['UndefinedTag:0xA434'])) $return['lens'] = trim($exif['UndefinedTag:0xA434']); if (!empty($exif['UndefinedTag:0xA434'])) $return['lens'] = trim($exif['UndefinedTag:0xA434']);
$return['latitude'] = ''; // Deal with GPS coordinates
$return['longitude'] = ''; if (!empty($exif['GPSLatitude']) && !empty($exif['GPSLatitudeRef']))
$return['latitude'] = getGPSCoordinate($exif['GPSLatitude'], $exif['GPSLatitudeRef']);
if (!empty($exif['GPSLongitude']) && !empty($exif['GPSLongitudeRef']))
$return['longitude'] = getGPSCoordinate($exif['GPSLongitude'], $exif['GPSLongitudeRef']);
} }

View File

@ -0,0 +1,28 @@
<?php
/**
* Returns the normalized coordinate from EXIF array.
* @return string Normalized coordinate as float number (degrees).
*/
function getGPSCoordinate($coordinate, $ref) {
$degrees = count($coordinate) > 0 ? gps2Num($coordinate[0]) : 0;
$minutes = count($coordinate) > 1 ? gps2Num($coordinate[1]) : 0;
$seconds = count($coordinate) > 2 ? gps2Num($coordinate[2]) : 0;
$flip = ($ref == 'W' || $ref == 'S') ? -1 : 1;
return $flip * ($degrees + (float)$minutes / 60 + (float)$seconds / 3600);
}
function formattedToFloatGPS($coordinate) {
$parts = explode('/', $coordinate, 2);
if (count($parts) <= 0)
return 0;
if (count($parts) == 1)
return $parts[0];
return (float)$parts[0] / $parts[1];
}
?>