This topic is locked

shows a map of the photo that has geo tagging

8/29/2012 5:16:26 AM
PHPRunner General questions
M
mumtaz author

Hello,
I tried to show a maps of a photo that has geo tagging with php runner.
Can it be done
what should I do to do it.
thx before

C
cgphp 8/29/2012

You can use the exif_read_data function to read headers from image: http://php.net/manual/en/function.exif-read-data.php

You can then map that info to a google map.

M
mumtaz author 8/31/2012



You can use the exif_read_data function to read headers from image: http://php.net/manual/en/function.exif-read-data.php

You 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&#xB0; %02d&#x2032; %05.2f&#x2033;", $sign, $degree, $minute, $second);

}
?>