Geotagging, for real this time
(THIS USED TO BE A FEW DIFFERENT POSTS)
Since I couldn’t figure out a free/painless way to edit a million photos’ EXIF data, I made a shortcode instead, and will just enter locations by hand in the post.
The basics
I put this in my theme’s functions.php file:
function geotag($atts) {
extract(shortcode_atts(array(
'n' => '41.000', # default value if none entered in shortcode
'w' => '-93.000', # default value if none entered in shortcode
't' => 'Earth', # default value if none entered in shortcode
'z' => '16', # default value if none entered in shortcode
), $atts));
# do it
return "Location: {$n}° N, {$w}° E (<a href=\"http://maps.google.com/maps?q={$n}+{$w}&t=h&z={$z}&output=embed">Gmap!</a>)";
}
add_shortcode('geo', 'geotag');
And the shortcode looks like this:
[geo t="The Space Needle" n="47.620484" w="-122.349544" z="19"]
A-and typing THAT into your post (or image caption) gives you THIS:
Location: 47.620484° N, -122.349544° E (Gmap!)
NOTES:
- The highlighted portion in the code snippet is for a no-whitespace, all map view of the Gmap (good for popups or iframes).
- Go here to learn all about the parameters for Google Maps URLs. That’s what I did.
- This post probably won’t be much help if you know even less php than me. If you click all the links, it will explain the rest of it better than I can. (I am mostly writing all this down in case I suffer a blow to the head and suddenly forget everything.)
- The default coordinates are a reference to the greatest song ever recorded.
- ????
- Profit!
Getting fancy
There are a few different ways you can display the map info, all of which I’ve tried, and only one of which I liked. I’ll save that one for last.
A regular old link
Since I hate popups so much, and had a long stretch where I couldn’t get the thickbox/iframe method to work, I settled for this:
return "Location: {$n}° N, {$w}° E (<a href=\"http://maps.google.com/maps?q={$n}+{$w}&ll={$n},{$w}&t=h&z={$z}\"
target=\"_blank\" title=\"{$t} (opens in new window, sorry)\">Gmap!</a>)";
A popup
If you don’t hate popups, and don’t think any of your readers will mind, here you go (note the use of the optional bits from the original snippet):
return "Location: {$n}° N, {$w}° E (<a href=\"http://maps.google.com/maps?q={$n}+{$w}&ll={$n},{$w}&t=h&z={$z}&output=embed\"
onclick=\"window.open('http://maps.google.com/maps?q={$n}+{$w}&ll={$n},{$w}&t=h&z={$z}&output=embed','popup','width=800,height=600,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=20,top=20'); return false\"
title=\"{$t} (popup, sorry)\">Gmap!</a>)";
Getting really fancy (Updated July 2010)
This is the one that gave me so much grief trying to figure out. It requires jquery and shadowbox to work, and displays the map in a purty iframe, with none of the problems thickbox had.
Edit the “do it” part:
return "Location: {$n}° N, {$w}° E (<a href=\"http://maps.google.com/maps?q={$n}+{$w}&ll={$n},{$w}&t=h&z={$z}&output=embed\" rel=\"shadowbox;width=800;height=600;\" title=\"{$t}\">Gmap!</a>)";
You can, of course, set the width and height to whatever you want, or accept the shadowbox defaults.
Oh, just stop it (Updated July 2010)
So, what if you want to make an inline link, like, with text?
function igeotag($atts) {
extract(shortcode_atts(array(
'l' => 'linkytext', # default value if none entered in shortcode
'n' => '41.000', # default value if none entered in shortcode
'w' => '-93.000', # default value if none entered in shortcode
't' => 'Earth', # default value if none entered in shortcode
'z' => '16', # default value if none entered in shortcode
), $atts));
# do it
return "<a href=\"http://maps.google.com/maps?q={$n}+{$w}&ll={$n},{$w}&t=h&z={$z}&output=embed\" rel=\"shadowbox;width=800;height=600;\" title=\"{$t}\">{$l}</a>";
}
add_shortcode('igeo', 'igeotag');
And the shortcode looks like this:
[igeo l="SWEET" t="The Space Needle is hella sweet" n="47.620484" w="-122.349544" z="19"]
Which results in the word SWEET being a link!
Disclaimer
I suck at html, css, php, making any of the aforementioned valid, and the less mentioned about my documentation skills the better. So if anything blows up, it’s your problem (but I do reserve the right to laugh at you).
PS
On the next page is some outdated info I didn’t want to just chuck.









