getGPSCoordinate.php 757 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Returns the normalized coordinate from EXIF array.
  4. * @return string Normalized coordinate as float number (degrees).
  5. */
  6. function getGPSCoordinate($coordinate, $ref) {
  7. $degrees = count($coordinate) > 0 ? formattedToFloatGPS($coordinate[0]) : 0;
  8. $minutes = count($coordinate) > 1 ? formattedToFloatGPS($coordinate[1]) : 0;
  9. $seconds = count($coordinate) > 2 ? formattedToFloatGPS($coordinate[2]) : 0;
  10. $flip = ($ref == 'W' || $ref == 'S') ? -1 : 1;
  11. return $flip * ($degrees + (float)$minutes / 60 + (float)$seconds / 3600);
  12. }
  13. function formattedToFloatGPS($coordinate) {
  14. $parts = explode('/', $coordinate, 2);
  15. if (count($parts) <= 0) return 0;
  16. if (count($parts) == 1) return $parts[0];
  17. return (float)$parts[0] / $parts[1];
  18. }
  19. ?>