Since Nokia Beta Labs just released a brilliant little program called Location Tagger, I have configured my WordPress blog to automatically geo tag my blog posts.

Nokia Location Tagger starts when I activate the camera on my Nokia N95, connecting to the satellites, getting my position. This position is written to the EXIF info on the jpg pictures, that I publish to my blog via e-mail, directly from the phone.

So now all my blog posts will have Geo Tagging, without me even thinking about it… :)

(The picture above showing Marienlyst School, the view from my office.)

Update:

To make this work with WordPress, I have made som changes in the postie-functions.php file. This is probably pretty dirty code, but it works like a glove. Feel free to edit, comment and improve.

The first thing you have to do is to increase the number of decimals that PHP uses when calculating things because you need more than 12 decimals when you convert GPS Degree postition to GPS Decimal positions. Add this line in the beginning for you the postie-functions.php

ini_set(‘precision’,25);

Next is to edit the function that writes the new post to the database. The edited version of the PostToDB function should look like this:

function PostToDB($details) {
global $wpdb;
$config = GetConfig();
if ($config["POST_TO_DB"]) {
//generate sql for insertion
$_POST['publish'] = true; //Added to make subscribe2 work – it will only handle it if the global varilable _POST is set
$post_ID = wp_insert_post($details);
global $gpsData;
echo $gpsData[0];

if ($gpsData[0]<>“”) //if GPS data found in photo, write GPSData to database
{
delete_post_meta($post_ID, ‘_geo_location’);
add_post_meta($post_ID, ‘_geo_location’, $gpsData[0].”,”.$gpsData[1]);
}

//do_action(‘publish_post’, $post_ID); – no longer needed
//do_action(‘publish_phone’, $post_ID); — seems to triger a double

}
}

Then you have to add the function that reads the EXIF infor from you JPG file. Add these two functions anywhere in your php file:

function degree2decimal($degrees, $minutes, $seconds, $direction)
{
$slashpos=strpos($seconds,’/');
$sec1 = substr($seconds,0,$slashpos);
$sec2 = substr($seconds,$slashpos+1,strlen($seconds));

$seconds = $sec1 / $sec2;

//echo “DIR: “.$direction;

$seconds=($seconds/60);
$minutes=($minutes+$seconds);
$minutes=($minutes/60);
$decimal=($degrees+$minutes);
//South latitudes and West longitudes need to return a negative result
if (($direction==”S”) or ($direction==”W”))
{ $decimal=$decimal*(-1);
}
return $decimal;
}

function getGPSdata($filnavn)
{
$exif = exif_read_data($filnavn, 0, true);
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
//echo $name.”.”.$key.”:”.$val.”
“;
if ($name==”GPSLatitude”)
{

$lat = degree2decimal($exif["GPS"]["GPSLatitude"][0],$exif["GPS"]["GPSLatitude"][1],$exif["GPS"]["GPSLatitude"][2],$exif["GPS"]["GPSLatitudeRef"]);

//echo “LATITUDE: “.$lat.”
“;

}
if ($name==”GPSLongitude”)
{

$lon = degree2decimal($exif["GPS"]["GPSLongitude"][0],$exif["GPS"]["GPSLongitude"][1],$exif["GPS"]["GPSLongitude"][2],$exif["GPS"]["GPSLongitudeRef"]);
//echo “LONGITUDE: “.$lon.”
“;

}

}
}
$pos = array($lat,$lon);
return $pos;
}

Last step is to edit the GetContent function. Count 114 lines into that function (at the end for the case ‘image’ loop) you must add the following code:

global $gpsData;
$gpsData = getGPSdata(“../../../../main/wp-photos/”.$fullImage);

That’s that, and that’s all. You will now have the GPS info for the post in the _geo_location meta field for your post.

There are lots of GPS plugins available for WP, that will read this info and display it in your post.

Facebook comments:

Leave a Reply