Imbo\EventListener\ExifMetadata::parseGpsCoordinate PHP Method

parseGpsCoordinate() protected method

Parse GPS coordinates in hours/minutes/seconds-format to decimal degrees
protected parseGpsCoordinate ( string $coordinate, string $hemisphere ) : float
$coordinate string Coordinate in hours/minutes/seconds format
$hemisphere string Hemisphere identifier (N, E, S, W)
return float
    protected function parseGpsCoordinate($coordinate, $hemisphere)
    {
        $coordinates = explode(' ', $coordinate);
        for ($i = 0; $i < 3; $i++) {
            $part = explode('/', $coordinates[$i]);
            $parts = count($part);
            if ($parts === 1) {
                $coordinates[$i] = $part[0];
            } else {
                if ($parts === 2) {
                    $coordinates[$i] = floatval($part[0]) / floatval($part[1]);
                } else {
                    $coordinates[$i] = 0;
                }
            }
        }
        $sign = $hemisphere === 'W' || $hemisphere === 'S' ? -1 : 1;
        $degrees = $coordinates[0] + $coordinates[1] / 60 + $coordinates[2] / 3600;
        return $sign * $degrees;
    }