Phree

Joined: 31 Dec 2005 Posts: 254 Location: South Coast, UK
|
Posted: Thu May 29, 2008 11:29 pm Post subject: How To: Add Geotagging to your MMS site. |
|
|
Hi all,
you may or may not have read my posts in the "Anything PHP" forum about Geotagging on my site. Regardless, here's what I have done.
With many modern camera phones, GPS is either integrated or they have the ability to connect to an external GPS receiver. With this feature, comes the ability to 'tag' your images with your current GPS co-ordinates - Longitude, Latitude, Sea Elevation etc. Using some code, it's possible to add an icon under the image when displayed on your site. Click the icon and it will open Google Maps and show you the position where the image was taken. If you are interested in doing this yourself, here's what you need to do:
First things first, you need to check you have the exif module installed on your server. Run your phpinfo and search for 'exif' and see if it's installed. If it's not, ask your host kindly to install it (I had to do this and they did it no problem).
Now, open your index.php and find:
| Code: |
}elseif(eregi("gif",$media_ext) OR eregi("jpg",$media_ext) OR eregi("png",$media_ext)) {
$middle_of_page .= "\n\t<br><br><a href=\"$path_to_media$media_time$media_underscore$media_number$media_ext\" target=\"_new\">\n";
$middle_of_page .= "\t<img src=\"phpThumb.php?src=/mms/$path_to_media$media_time$media_underscore$media_number$media_ext&w=$display_image_max_size_w&h=$display_image_max_size_h&q=95\" class=\"main_pic_frame\" alt=\"$media_time$media_ext\" title=\"click for full-sized pic! - $datestamp\"></a>\n";
|
and directly underneath it, add this line:
| Code: |
$pictoshow = "$media_time$media_underscore$media_number$media_ext";
|
Now find this code:
| Code: |
if($allow_comments == "yes") {
if($password_protect_comments == "yes") {
show_comments($media_time);
echo "\t<br><a href=\"comments/comments.php?p=$p&media=$media_time\">Post a Comment!</a>\n\t<br>\n";
//echo "\t(Username: <b>guest</b> Password: <b>humpa</b>)<br>\n";
}else {
show_comments($media_time,"pic");
echo "\t<br><a href=\"comments.php?p=$p&media=$media_time\">Post a Comment!</a>\n\t<br>\n";
//show_comment_bar($media_time, "", "");
}
}
|
And directly after it, add this:
| Code: |
// GPS Start of Function
/**************************************************
Type: FUNCTION
Function: DegToDec
Purpose: Converts degrees to decimal
Input: $deg,$min,$sec Output: decimal value
Requires:
**************************************************/
function DegToDec($strRef,$intDeg,$intMin,$intSec)
{
$arrLatLong = array();
$arrLatLong["N"] = 1;
$arrLatLong["E"] = 1;
$arrLatLong["S"] = -1;
$arrLatLong["W"] = -1;
return ($intDeg+((($intMin*60)+($intSec))/3600)) * $arrLatLong[$strRef];
}
$arrPhotoExif = exif_read_data($path_to_media . $pictoshow,'GPS');
if($arrPhotoExif) { $arrLatDeg = split("/",$arrPhotoExif["GPSLatitude"][0]);
$intLatDeg = $arrLatDeg[0]/$arrLatDeg[1];
$arrLatMin = split("/",$arrPhotoExif["GPSLatitude"][1]);
$intLatMin = $arrLatMin[0]/$arrLatMin[1];
$arrLatSec = split("/",$arrPhotoExif["GPSLatitude"][2]);
$intLatSec = $arrLatSec[0]/$arrLatSec[1];
$arrLongDeg = split("/",$arrPhotoExif["GPSLongitude"][0]);
$intLongDeg = $arrLongDeg[0]/$arrLongDeg[1];
$arrLongMin = split("/",$arrPhotoExif["GPSLongitude"][1]);
$intLongMin = $arrLongMin[0]/$arrLongMin[1];
$arrLongSec = split("/",$arrPhotoExif["GPSLongitude"][2]);
$intLongSec = $arrLongSec[0]/$arrLongSec[1];
// round to 6 = approximately 1 meter accuracy
$intLatitude = round(DegToDec($arrPhotoExif["GPSLatitudeRef"], $intLatDeg,$intLatMin,$intLatSec),6);
$intLongitude = round(DegToDec($arrPhotoExif["GPSLongitudeRef"], $intLongDeg,$intLongMin,$intLongSec), 6);
echo '<a href=http://maps.google.com/maps?f=q&hl=en&geocode=&q=' ;
echo $intLatitude;
echo "+" ;
echo $intLongitude;
echo "&spn=0.0,0.0&t=h&z=16&t=h&hl=en\" target=\"_blank\"><img src=gpsicon.jpg border=0 width=25 height=25 alt='View this location in Google Maps'></a>";
}
// GPS End
|
The only other thing you need to do, is add your GPS icon and upload it to your main MMS directory. If you want the icon I use, here it is:
You do of course need a GPS equipped device, either integral or something that will connect to your device such as an external bluetooth receiver. I have a Nokia N95 and run some software on it called Location Tagger. This is what tags my images and it can be found here. One small problem I found was that when sending an image, it would reduce the size fit for an MMS - and that strips out all the GPS data. To combat this, I simply changed the image size that my phone takes to 640x480 and then changed my MMS profile to send image size "original" - and that works just great. Images are around 100kb.
If you'd like to see this in action, please feel free to visit my site here. |
|