Skip to content

Commit

Permalink
GPS Daten auslesen
Browse files Browse the repository at this point in the history
Auslesen der GPS Daten und umrechnen in Grad.
  • Loading branch information
Tony Münzberg committed Jan 17, 2018
1 parent 2d24b13 commit 2184ddd
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion lib/rex_mediapool_exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class rex_mediapool_exif
'keywords' => 'Keywords',
'title' => ['DocumentTitle', 'Headline'],
'description' => 'Caption',
'categories' => 'Subcategories'
'categories' => 'Subcategories',
'gps' => 'GPSCoordinates',
];

public static function processUploadedMedia(rex_extension_point $ep)
Expand Down Expand Up @@ -180,6 +181,10 @@ protected static function getExifData(rex_media $media)
$path = rex_path::media($media->getFileName());
if($exif = exif_read_data($path, 'ANY_TAG'))
{
if($exif['GPSLatitude'] && $exif['GPSLatitudeRef'] && $exif['GPSLongitude'] && $exif['GPSLongitudeRef']) {
$exif['GPSCoordinates'] = static::convertGPSCoordinates($exif['GPSLatitude'], $exif['GPSLatitudeRef'], $exif['GPSLongitude'], $exif['GPSLongitudeRef']);
}

return $exif;
}
}
Expand Down Expand Up @@ -241,4 +246,32 @@ protected static function getIptcData(rex_media $media)

return $return;
}
protected static function convertGPSCoordinates($GPSLatitude, $GPSLatitude_Ref, $GPSLongitude, $GPSLongitude_Ref)
{
$GPSLatfaktor = 1;
$GPSLongfaktor = 1;

if($GPSLatitude_Ref == 'S') $GPSLatfaktor = -1;
if($GPSLongitude_Ref == 'W') $GPSLongfaktor = -1;

$GPSLatitude_h = explode("/", $GPSLatitude[0]);
$GPSLatitude_m = explode("/", $GPSLatitude[1]);
$GPSLatitude_s = explode("/", $GPSLatitude[2]);

$GPSLat_h = $GPSLatitude_h[0] / $GPSLatitude_h[1];
$GPSLat_m = $GPSLatitude_m[0] / $GPSLatitude_m[1];
$GPSLat_s = $GPSLatitude_s[0] / $GPSLatitude_s[1];

$GPSLatGrad = $GPSLatfaktor * ($GPSLat_h + ($GPSLat_m + ($GPSLat_s / 60)) / 60);

$GPSLongitude_h = explode("/", $GPSLongitude[0]);
$GPSLongitude_m = explode("/", $GPSLongitude[1]);
$GPSLongitude_s = explode("/", $GPSLongitude[2]);
$GPSLong_h = $GPSLongitude_h[0] / $GPSLongitude_h[1];
$GPSLong_m = $GPSLongitude_m[0] / $GPSLongitude_m[1];
$GPSLong_s = $GPSLongitude_s[0] / $GPSLongitude_s[1];
$GPSLongGrad = $GPSLongfaktor * ($GPSLong_h + ($GPSLong_m + ($GPSLong_s / 60)) / 60);

return number_format($GPSLatGrad, 6,'.','') . ',' . number_format($GPSLongGrad, 6,'.','');
}
}

0 comments on commit 2184ddd

Please sign in to comment.