lychee/php/helpers/getGPSCoordinate.php

30 lines
757 B
PHP
Raw Normal View History

2016-04-17 19:59:50 +00:00
<?php
/**
* Returns the normalized coordinate from EXIF array.
* @return string Normalized coordinate as float number (degrees).
*/
function getGPSCoordinate($coordinate, $ref) {
2016-04-18 07:40:52 +00:00
2016-04-17 20:24:12 +00:00
$degrees = count($coordinate) > 0 ? formattedToFloatGPS($coordinate[0]) : 0;
2016-04-18 07:40:52 +00:00
$minutes = count($coordinate) > 1 ? formattedToFloatGPS($coordinate[1]) : 0;
$seconds = count($coordinate) > 2 ? formattedToFloatGPS($coordinate[2]) : 0;
$flip = ($ref == 'W' || $ref == 'S') ? -1 : 1;
2016-04-17 19:59:50 +00:00
2016-04-18 07:40:52 +00:00
return $flip * ($degrees + (float)$minutes / 60 + (float)$seconds / 3600);
2016-04-17 19:59:50 +00:00
}
function formattedToFloatGPS($coordinate) {
2016-04-18 07:40:52 +00:00
2016-04-17 19:59:50 +00:00
$parts = explode('/', $coordinate, 2);
2016-04-18 07:40:52 +00:00
if (count($parts) <= 0) return 0;
if (count($parts) == 1) return $parts[0];
return (float)$parts[0] / $parts[1];
2016-04-17 19:59:50 +00:00
}
?>