|
You can use the exif_read_data function to read headers from image: http://php.net/manual/en/function.exif-read-data.phpYou can then map that info to a google map. I've found the geotagging function.
I store these functions in the folder "include". I call these functions through "after application initialized" with the following code:
include ("include / geo.php"); then I made "after record added" with the following code:
$c = getCoordinates ('files /'. $ values ['pic']);
$ latitude = $ c [0];
$ longitude = $ c [1]; $ values ['lat'] = '$ latitude ";
$ values ["long"] = "$ longitude";
but the "lat" and "long" still could not fill the code latitude or longitude of the image file this file geo.php
<?php function exifToNumber($value, $format) {
$spos = strpos($value, '/');
if ($spos === false) {
return sprintf($format, $value);
} else {
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);
} ?>
|