Flickr geoRSS Google Maps via WordPress Shortcode

Ever wanted to add nice V3 Google Maps to your website to show off your geo-tagged RSS stream? Want to be able to reuse code where possible to make life easier? If you try to do this using the standard wordpress wysiwyg editor the text will get malformed. One simple way to do this is to add the short code to your theme functions.php file, and call the javascript.

Following on from an excellent tutorial from the cats who code blog, a few simple modifications and we now have a simple way to call a Version 3 Google maps linked to any external geoRss feed.

Open up your theme, via: Appearance Editor > functions.php, or via your ftp editor of choice

First, back up your functions.php file, next, add:

function showflickrmap($atts) {
extract(shortcode_atts(array(
		'latlong' => '',
		'groupid' => '',
), $atts));
return '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
<!--
function initialize() {
	var myLatlng = new google.maps.LatLng('.$latlong.');
  var myOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }

  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  var georssLayer = new google.maps.KmlLayer("http://api.flickr.com/services/feeds/geo/?g='.$groupid.'@N20&lang=en-us&format=rss_200");

  georssLayer.setMap(map);
}
-->
</script>
<div id="map_canvas" style="margin:20px;width:95%;height:450px;border:1px solid #000;"></div>

<script type="text/javascript">
window.onload=initialize(); 
</script>';
}

add_shortcode('flickrmap', 'showflickrmap');

Make your your syntax is correct, and save the functions.php file. If you get the “Whitescreen of death” make sure there are no line breaks or whitespace at the end of your functions file.

What we’ve done here is set up an array at the start with our attributes (latlong,groupid), then we can call the map by simply adding:

[flickrmap latlong="40.7114,-73.8784" groupid="1709477"]

to our page. Simply edit the start latitude/longitude, and change the “grouped” to suit. You could go further, and change the zoom point, etc.

Want to see the results? jump over to TrooperTrek and check out his Across Australia adventure wearing stormtrooper armor!

Hope this helps someone.

Simple Jquery CSS Tabs and V3 Google Maps

I had a recent need at work to create tabbed content using Jquery, and include V3 Google maps. Simple right? not likely.

Thanks to Google, I came across an awesome post from Soh Tanaka, posted back in 2009. This was the perfect solution for Jquery tabs, but after a quick embed of google map code, revealed an issue with the version 3 Google map (in a hidden tab), which was loading off center.

Another search on Google revealed this was a bit of a problem, with a few fixes, but none that really worked for me. It turns out that due to the use of the Jquery class “.hide();” google has no reference point for loading the map into the center, meaning it was loading into the top left.

Jquery and CSS Tabs with Version 3 Google maps

To give the map a reference point, I had to first define some CSS to both the map tab, and the map container, then re-initialize the map function call. I simply added an ID to my map tab link, and used that to call my function.

	
// Function added to help reset map and container boundaries
        $("#showMap").click(function() {
        $("#tab2").css({'display':'block'});
        $("#map_canvas").css({'width':'630px', 'height':'400px'});
        initialize();
        });

This defined my width and height of both the tab for the content, and my google map, giving it a reference point for the map.

I did have some issues in Internet Explorer, when tabbing between content, reloading the map, resizing the window manually, tabbing, relaoding etc, but this seems to have been fixed (empty function call in the header left for anyone wishing to play with it).

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="_LANGUAGE" xml:lang="_LANGUAGE">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple Jquery CSS Tabs and V3 Google Maps</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
<!--
$(document).ready(function() {
	//Default Action
	$(".tab_content").hide();
	$("ul.tabs li:first").addClass("active").show(); 
	$(".tab_content:first").show(); 
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active"); 
		$(".tab_content").hide(); 
		var activeTab = $(this).find("a").attr("href"); 
		$(activeTab).fadeIn();
		if(activeTab == '#tab2') {      
			$(window).resize(function(){
			//$("#tab2").css({'display':'block'});
			//$("#map_canvas").css({'width':'630px', 'height':'400px'});
			//initialize();
			//alert('Changed!');
			}); 
    		}	
		return false;
	});
});
-->
</script>

<style type="text/css" media="screen">
<!--
/* Standard definitions  */
body{font:normal 76.1% "Trebuchet MS", Arial, Helvetica, sans-serif;color:#151515;background:#eaeaea;margin:20px;}
h1{font-size:2.2em;margin:20px 0;}
a:link,a:active,a:visited{background-color:transparent;color:#7aa200;}
a:hover{background-color:transparent;color:#a22600;}
/* Extras  */
.backtohome{border:1px solid #dbdbdb;background-color:#f5f5f5;color:#8f8f8f;-webkit-border-radius:5px 5px 5px 5px;-moz-border-radius:5px;border-radius:5px 5px 5px 5px;padding:5px;}
.hdot{height:1px;border-top:1px dotted #dbdbdb;}
/* Tabbed interface */
.container {width: 670px; margin: 10px auto;}
ul.tabs {margin: 0;padding: 0;float: left;list-style: none;height: 32px;border-bottom: 1px solid #c0c0c0;border-left: 1px solid #c0c0c0;width: 100%;}
ul.tabs li {float: left;margin: 0;padding: 0;height: 31px;line-height: 31px;border: 1px solid #c0c0c0;border-left: none;margin-bottom: -1px;background: #e0e0e0;overflow: hidden;position: relative;}
ul.tabs li a {text-decoration: none;color: #000;display: block;padding: 0 20px;border: 1px solid #fff;outline: none;}
ul.tabs li a:hover {background: #ccc;}	
html ul.tabs li.active, html ul.tabs li.active a:hover  {background: #fff;border-bottom: 1px solid #fff;}
.tab_container {	border: 1px solid #c0c0c0;border-top: none;clear: both;float: left; width: 100%;background: #fff;
-webkit-border-radius: 0px 0px 5px 5px;-moz-border-radius: 0px 0px 5px 5px;border-radius: 0px 0px 5px 5px;}
.tab_content {padding: 20px;}
.tab_content h2 {padding-bottom: 10px;border-bottom: 1px dotted #ddd;}
.tab_content h3 a{color: #254588;}
/* Google map */
#map_canvas {width: 630px; height: 400px;border:1px solid #dbdbdb;}
-->
</style>
</head>
<body>
<div class="container">
	<h1>Simple Jquery CSS Tabs and V3 Google Maps</h1>

    <ul class="tabs">
    <li><a href="#tab1">About</a></li>
    <li><a href="#tab2" id="showMap">Map</a></li>
    <li><a href="#tab3">Contact</a></li>
    </ul>
<!-- Start tab container -->
<div class="tab_container">

    <div id="tab1" class="tab_content">
            <h2>About</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </div>

    <div id="tab2" class="tab_content">
    <h2>Google Map</h2>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" language="javascript">
    //<![CDATA[
    $(document).ready(function() {
    
      function initialize() {
        var myLatlng = new google.maps.LatLng(-31.952222,115.858889);
        var myOptions = {
          zoom: 14,
          center: myLatlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        
        var contentString = '<div id="content">'+
            '<h1>Perth, Western Australia</h1>'+
            '<div>'+
            '<p><b>Perth</b> is the capital and largest city of the Australian state of Western Australia and the fourth most populous city in Australia</p>'+
            '<p>Attribution: Perth, Western Australia, <a href="http://en.wikipedia.org/wiki/Perth,_Western_Australia">'+
            'http://en.wikipedia.org/wiki/Perth,_Western_Australia</a></p>'+
            '</div>'+
            '</div>';
    
        var infowindow = new google.maps.InfoWindow({
            content: contentString,
            maxWidth: 300
        });
    
        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title: 'Perth, Western Australia'
        });
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });
    
      }
    	// Function added to help reset map and container boundaries
        $("#showMap").click(function() {
        $("#tab2").css({'display':'block'});
        $("#map_canvas").css({'width':'630px', 'height':'400px'});
        initialize();
        //alert('showMap Clicked!');
        });
        
     initialize(); 

    });
    //]]>
    </script>
    <div id="map_canvas" style="width:630px;height:400px;"></div>
    </div>

    <div id="tab3" class="tab_content">
		<h2>Contact</h2>
            	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                </p>
    </div>
    
</div>
<!-- End tab container -->

<!-- Back Home Footer -->
<div style="clear: both; display: block; padding: 10px 0; text-align:center;">
<div class="backtohome">
<p><a href="http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery">Simple Tabs w/ CSS &amp; jQuery</a> by Soh Tanaka. | 
<a href="http://flintmaker.com">&laquo; Back to Flintmaker</a>
</p>
</div>
</div>
<!-- end back home Footer -->
</div>
</body>
</html>

Enough reading, have a play with the demo, feedback, fixes and improvements appreciated and will be added to the code.

Demo

View Demo

Popup window using Jquery

The use of popup windows has diminished due to more restrictive browser security settings, and methods such as modal windows (think lightbox). However, if you don’t want to add the bloat of yet another plugin to your website, and have a need for it, simply add the following code to your main javascript file:

jQuery('a.popup').live('click', function(){
	newwindow=window.open($(this).attr('href'),'','height=300,width=500');
	if (window.focus) {newwindow.focus()}
	return false;
});

Now simply add it to your link like:

<a href="blah.html" class="popup">View Blah</a>

Jquery fade message in or out

The ability to have a div fade in or out after a specified amount of time has the advantage of both visually attracting the users focus to an area, and saving space on the page. Thankfully, Jquery allows to do this easily.

This code is particlarly useful for delivering form responses such as an alert, or success notification. This first code example shown is used on the document ready, and uses .remove(); to get rid of the div after it has been shown, so, may not be practical for all uses.

Javascript:

$(document).ready(function(){
setTimeout(function(){
$("div.successful").fadeOut("slow", function () {
$("div.successful").remove();
});

}, 5000);
});

Now we just need to create a div which we have targeted (in this case, I created “successful”).

<div class="successful">
<h2>Thanks, your form has been sent!</h2>
</div>

I have my example set to 5 seconds (5000), change this to whatever you want.

Calling the functions on demand (and not removing the div):

We can also call these kinds of alerts when required (ie for successful/bad form submissions, alerts, etc. This method is a little nicer, as we aren’t required to reload the page to bring back the div.

Javascript:

$(document).ready(function() {
$("#messageBox").addClass("messagebox");setTimeout(function(){
$("#messageBox").fadeOut("slow")}, 4000);
});
function messagebox(){
$("#messageBox").removeClass().addClass("confirmbox").html("Item has been saved").fadeIn(2000).fadeOut(4000);
}
function alertbox(){
$("#messageBox").removeClass().addClass("errorbox").html("Oops, there was an error!").fadeIn(2000).fadeOut(4000);
}

You wouold call them simply by:

<a href="javascript:messagebox();">Click to Show a confirm box</a> | <a href="javascript:alertbox();">Click to show an Alert box</a>

To see how this works, copy the text below, save it to your desktop and try it out:

< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="_LANGUAGE" xml:lang="_LANGUAGE">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple Alert/Confirm Box</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
<!--
$(document).ready(function() {
$("#messageBox").addClass("messagebox");setTimeout(function(){
$("#messageBox").fadeOut("slow")}, 4000);
});
function messagebox(){
$("#messageBox").removeClass().addClass("confirmbox").html("Item has been saved").fadeIn(2000).fadeOut(4000);
}
function alertbox(){
$("#messageBox").removeClass().addClass("errorbox").html("Oops, there was an error!").fadeIn(2000).fadeOut(4000);
}
-->
</script>
<style type="text/css" media="screen">
<!--
.container {width: 670px; margin: 10px auto;}
.messagebox {background-color: #F5F5F5;padding:5px;margin:10px 0px;border: 1px solid #DBDBDB;}
.errorbox {color:#000;background-color:#ffeded;padding:5px;margin:10px 0px;border:1px solid #f27c7c;}
.confirmbox {background-color:#F2FFDB;color:#151515;border:1px solid #9C6;margin:10px 0px;padding:5px;}
-->
</style>

</head>
<body>
<div class="container">
<h1>Simple Alert/Confirm Box</h1>
<div class="messagebox" id="messageBox">This content will fade out in 4 seconds.</div>

<a href="javascript:messagebox();">Click to Show a confirm box</a> | <a href="javascript:alertbox();">Click to show an Alert box</a>
</div>

</body>
</html>

Want to see it in action? have a play with the demo, feedback, fixes and improvements appreciated and will be added to the code.

Demo

View Demo

Print

[slide_description_bold button_link=# button_text="Read more"]

Print

Business Cards, Brochures, Corporate folios and more
[/slide_description_bold]
[slide_pic_small]

[/slide_pic_small]

Develop

[slide_description_bold button_link=# button_text="Read more"]

Develop

PHP, iPhone, and database driven applications
[/slide_description_bold]
[slide_pic_small]
Develop
[/slide_pic_small]

Design

[slide_description_bold button_link=# button_text="Read more"]

Design

Logos, Corporate Identity, Brochures, and Websites.
[/slide_description_bold]
[slide_pic_small]
Design
[/slide_pic_small]