From e2509b16570e56ca4a11fffb024459d739d8aa2a Mon Sep 17 00:00:00 2001 From: Quentin Ligier Date: Sun, 17 Apr 2016 21:59:50 +0200 Subject: [PATCH] Import GPS coordinates from EXIF --- php/Modules/Photo.php | 7 +++++-- php/helpers/getGPSCoordinate.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 php/helpers/getGPSCoordinate.php diff --git a/php/Modules/Photo.php b/php/Modules/Photo.php index bb4f5e0..52dead3 100755 --- a/php/Modules/Photo.php +++ b/php/Modules/Photo.php @@ -819,8 +819,11 @@ final class Photo { if (!empty($exif['UndefinedTag:0xA434'])) $return['lens'] = trim($exif['UndefinedTag:0xA434']); - $return['latitude'] = ''; - $return['longitude'] = ''; + // Deal with GPS coordinates + 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']); } diff --git a/php/helpers/getGPSCoordinate.php b/php/helpers/getGPSCoordinate.php new file mode 100644 index 0000000..391c777 --- /dev/null +++ b/php/helpers/getGPSCoordinate.php @@ -0,0 +1,28 @@ + 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]; +} + +?> \ No newline at end of file