/
geo.php
54 lines (45 loc) · 1.46 KB
/
geo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
function exifToNumber($value, $format) {
$spos = strpos($value, '/');
if ($spos === false) {
return sprintf($format, $value);
} else {
// list($base,$divider) = split("/", $value, 2);
list($base,$divider) = explode("/", $value, 2);
if ($divider == 0)
return sprintf($format, 0);
else
return sprintf($format, ($base / $divider));
}
}
function exifToCoordinate($reference, $coordinate) {
if ($reference == 'S' || $reference == 'W')
$prefix = '-';
else
$prefix = '';
return $prefix . sprintf('%.6F', exifToNumber($coordinate[0], '%.6F') +
(((exifToNumber($coordinate[1], '%.6F') * 60) +
(exifToNumber($coordinate[2], '%.6F'))) / 3600));
}
function getCoordinates($filename) {
if (extension_loaded('exif')) {
$exif = @exif_read_data($filename, 'EXIF');
if (isset($exif['GPSLatitudeRef']) && isset($exif['GPSLatitude']) &&
isset($exif['GPSLongitudeRef']) && isset($exif['GPSLongitude'])) {
return array (
exifToCoordinate($exif['GPSLatitudeRef'], $exif['GPSLatitude']),
exifToCoordinate($exif['GPSLongitudeRef'], $exif['GPSLongitude'])
);
}
}
}
function coordinate2DMS($coordinate, $pos, $neg) {
$sign = $coordinate >= 0 ? $pos : $neg;
$coordinate = abs($coordinate);
$degree = intval($coordinate);
$coordinate = ($coordinate - $degree) * 60;
$minute = intval($coordinate);
$second = ($coordinate - $minute) * 60;
return sprintf("%s %d° %02d′ %05.2f″", $sign, $degree, $minute, $second);
}
?>