<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Duncan's blog</title>
	<atom:link href="http://duncan99.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://duncan99.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Wed, 07 Dec 2011 18:46:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='duncan99.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Duncan's blog</title>
		<link>http://duncan99.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://duncan99.wordpress.com/osd.xml" title="Duncan&#039;s blog" />
	<atom:link rel='hub' href='http://duncan99.wordpress.com/?pushpress=hub'/>
		<item>
		<title>ColdFusion query-of-queries, tips for adding dynamic columns</title>
		<link>http://duncan99.wordpress.com/2011/11/10/coldfusion-query-of-queries-tips-for-adding-dynamic-columns/</link>
		<comments>http://duncan99.wordpress.com/2011/11/10/coldfusion-query-of-queries-tips-for-adding-dynamic-columns/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 17:35:23 +0000</pubDate>
		<dc:creator>duncan</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[cfml]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[query of queries]]></category>

		<guid isPermaLink="false">http://duncan99.wordpress.com/?p=1497</guid>
		<description><![CDATA[Supposing you&#8217;re doing a query of queries, and you want to add a dynamic column, perhaps based on a mixture of existing CF variables and values from the original query. There are a few gotchas to watch out for. Firstly, you have to use single quotes &#8216; &#8216; instead of double quotes &#8221; &#8221; for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1497&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Supposing you&#8217;re doing a <a href="http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0e4fd-7ff0.html#WSf01dbd23413dda0e-473edbc812013c12636-7ffd">query of queries</a>, and you want to add a dynamic column, perhaps based on a mixture of existing CF variables and values from the original query.  There are a few gotchas to watch out for.</p>
<p><strong>Firstly</strong>, you have to use single quotes &#8216; &#8216; instead of double quotes &#8221; &#8221; for anything in the string.  This is contrary to ColdFusion&#8217;s normal allowance for any mixture, e.g. this is usually perfectly fine:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;cfset x = "hi" &amp; 'hi'&gt;</pre>
<p>However when trying to use &#8221; &#8221; in the query-of-queries, it throws the error:</p>
<blockquote><p><em>Query Of Queries syntax error.<br />
Encountered &#8220;. Lexical error at line 3, column 25. Encountered: &#8220;\&#8221;" (34), after : &#8220;&#8221;</em></p></blockquote>
<p>This query will throw that error:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;cfquery name="rstGetStuff" dbtype="query"&gt;
	SELECT 	"Hello World" AS columnName
	FROM rstOriginalQuery
&lt;/cfquery&gt;</pre>
<p>But this is fine:</p>
<pre style="font-size:larger;white-space:pre-wrap;">
&lt;cfquery name="rstGetStuff" dbtype="query"&gt;
	SELECT 	'Hello World' AS columnName
	FROM rstOriginalQuery
&lt;/cfquery&gt;</pre>
<p><strong>Secondly</strong>, if you&#8217;re wanting to refer to variables within that string, just add them into the string surrounded by # #.  Again, contrary to normal CFML, where these are equivalent:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;cfset x = "hi " &amp; variables.strName&gt;
&lt;cfset x = "hi #variables.strName#"&gt;
</pre>
<p>So this throws the error:</p>
<blockquote><p><em>Query Of Queries syntax error.<br />
Encountered &#8220;.. Incorrect Select Statement, Expecting a &#8216;FROM&#8217;, but encountered &#8216;.&#8217; instead, A select statement should have a &#8216;FROM&#8217; construct. </em></p></blockquote>
<pre style="font-size:larger;white-space:pre-wrap;">
&lt;cfset strName = "Duncan"&gt;

&lt;cfquery name="rstGetStuff" dbtype="query"&gt;
	SELECT 	'Hello ' + strName AS columnName
	FROM rstOriginalQuery
&lt;/cfquery&gt;</pre>
<p>Instead you have to do</p>
<pre style="font-size:larger;white-space:pre-wrap;">
&lt;cfquery name="rstGetStuff" dbtype="query"&gt;
	SELECT 	'Hello #strName#' AS columnName
	FROM rstOriginalQuery
&lt;/cfquery&gt;</pre>
<p><strong>Thirdly</strong>, if you&#8217;re wanting to add values from the original query into that dynamic column, you might need to <a href="http://www.grantshepert.com/post.cfm/dynamic-data-types-for-coldfusion-query-of-queries">CAST it to the correct type</a>.  In this case I have a column in the original query, intIDColumn, that is a numeric ID.  </p>
<p>This throws the error:</p>
<blockquote><p><em>Query Of Queries runtime error.<br />
Cannot mix types INTEGER and VARCHAR in a + binary operation. </em></p></blockquote>
<pre style="font-size:larger;white-space:pre-wrap;">
&lt;cfquery name="rstGetStuff" dbtype="query"&gt;
	SELECT 	'/some/url/path/' + intIDColumn + '/' AS strURL
	FROM rstOriginalQuery
&lt;/cfquery&gt;</pre>
<p>Instead I have to cast it to a VARCHAR when trying to add it into my string.</p>
<pre style="font-size:larger;white-space:pre-wrap;">
&lt;cfquery name="rstGetStuff" dbtype="query"&gt;
	SELECT 	'/some/url/path/' + CAST(intIDColumn AS VARCHAR) + '/' AS strURL
	FROM rstOriginalQuery
&lt;/cfquery&gt;</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/duncan99.wordpress.com/1497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/duncan99.wordpress.com/1497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/duncan99.wordpress.com/1497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/duncan99.wordpress.com/1497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/duncan99.wordpress.com/1497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/duncan99.wordpress.com/1497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/duncan99.wordpress.com/1497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/duncan99.wordpress.com/1497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/duncan99.wordpress.com/1497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/duncan99.wordpress.com/1497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/duncan99.wordpress.com/1497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/duncan99.wordpress.com/1497/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/duncan99.wordpress.com/1497/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/duncan99.wordpress.com/1497/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1497&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://duncan99.wordpress.com/2011/11/10/coldfusion-query-of-queries-tips-for-adding-dynamic-columns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5594b71e9f54f3e73f6294b054f5616?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">duncan</media:title>
		</media:content>
	</item>
		<item>
		<title>Google Maps API &#8211; adding infowindows in response to user clicks</title>
		<link>http://duncan99.wordpress.com/2011/11/04/google-maps-api-adding-infowindows-in-response-to-user-clicks/</link>
		<comments>http://duncan99.wordpress.com/2011/11/04/google-maps-api-adding-infowindows-in-response-to-user-clicks/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 13:58:29 +0000</pubDate>
		<dc:creator>duncan</dc:creator>
				<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[google maps api]]></category>
		<category><![CDATA[infowindow]]></category>
		<category><![CDATA[infowindows]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://duncan99.wordpress.com/?p=1483</guid>
		<description><![CDATA[In response to my previous post about adding infowindows with the Google Maps API, Frank B asked if it was possible &#8220;to write a script where the user clicks on the map, and an infowindow pops up in that location containing information about that place, say the county it belongs to&#8221;. Here&#8217;s a quick something [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1483&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In response to my previous post about <a href="http://duncan99.wordpress.com/2011/10/08/google-maps-api-infowindows/" title="Google Maps API – infowindows">adding infowindows with the Google Maps API</a>, Frank B asked if it was possible <em>&#8220;to write a script where the user clicks on the map, and an infowindow pops up in that location containing information about that place, say the county it belongs to&#8221;</em>.  Here&#8217;s a quick something I rustled up in response to that.</p>
<p>Firstly, let&#8217;s just open an infowindow on a map in response to user clicks on the map.</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;script type="text/javascript"&gt;
function initialize() {
	var myOptions = {
		zoom: 10,
		center: new google.maps.LatLng(50.820645,-0.137376),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	var infowindow =  new google.maps.InfoWindow({
		content: 'Hello World!'
	});

	google.maps.event.addListener(map, 'click', function(event) {
		infowindow.setPosition(event.latLng);
		infowindow.open(map);
	});
}

google.maps.event.addDomListener(window, 'load', initialize);
&lt;/script&gt;</pre>
<p>So we simply have an event listener for any click events on the map itself.  We can then find out the position of that click using event.latLng, which we can then pass to the setPosition function on the infowindow.  The final .open() simply shows the infowindow; if it&#8217;s already open, this won&#8217;t do anything (but it causes no harm to call it again).</p>
<p>This opens the same infowindow anywhere we click on the map:<br />
<a href="http://duncan99.files.wordpress.com/2011/11/google-maps-api-v3-lesson-3-infowindows-in-response-to-user-clicks-mozilla-firefox-03112011-235451.jpg"><img src="http://duncan99.files.wordpress.com/2011/11/google-maps-api-v3-lesson-3-infowindows-in-response-to-user-clicks-mozilla-firefox-03112011-235451.jpg" alt="" title="Google Maps API V3 lesson 3 - infowindows in response to user clicks - Mozilla Firefox 03112011 235451" width="370" height="277" class="aligncenter size-full wp-image-1485" /></a></p>
<p>Now, let&#8217;s get some content about each location we click on, and use that to dynamically set the content of the infowindow.  To do this we need to do a reverse Geocoding request (i.e. getting address details from a latlng coordinates).  The usual use of the Geocoding service is to do the opposite &#8211; find out the coordinates of an address.  </p>
<p>Interestingly Google&#8217;s <a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderRequest">API reference</a> says to use a &#8216;location&#8217; parameter but their <a href="http://code.google.com/apis/maps/documentation/javascript/services.html#GeocodingRequests">Developer documentation</a> says to use a &#8216;latLng&#8217; parameter.  Both seemed to work for me, but I&#8217;d say the API reference should be considered the correct source in general. </p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;script type="text/javascript"&gt;
var map, geocoder, infowindow;

function initialize() {
	var myOptions = {
		zoom: 10,
		center: new google.maps.LatLng(50.820645,-0.137376),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	geocoder = new google.maps.Geocoder();

	infowindow =  new google.maps.InfoWindow({
		content: ''
	});

	google.maps.event.addListener(map, 'click', function(event) {
		doGeocoding(event.latLng);
	});
}

function doGeocoding(latLng) {
	geocoder.geocode({'location': latLng}, function(results, status) {
		if (status == google.maps.GeocoderStatus.OK) {
			if (results[1]) {	// use 2nd array item, a less-specific address
				infowindow.setContent(results[1].formatted_address);
			} else {
				infowindow.setContent('');
			}
		} else {
			infowindow.setContent('no address found');
		}
	});

	infowindow.setPosition(latLng);
	infowindow.open(map);
}

google.maps.event.addDomListener(window, 'load', initialize);
&lt;/script&gt;</pre>
<p><a href="http://duncan99.files.wordpress.com/2011/11/google-maps-api-v3-lesson-3-infowindows-in-response-to-user-clicks-mozilla-firefox-04112011-075955.jpg"><img src="http://duncan99.files.wordpress.com/2011/11/google-maps-api-v3-lesson-3-infowindows-in-response-to-user-clicks-mozilla-firefox-04112011-075955.jpg" alt="" title="Google Maps API V3 lesson 3 - infowindows in response to user clicks - Mozilla Firefox 04112011 075955" width="419" height="314" class="aligncenter size-full wp-image-1491" /></a></p>
<p>This code does strange things for me when clicking on the area at sea.  If it&#8217;s the first click on the map, it doesn&#8217;t display any infowindow at all.  If I initially click on the land to get an address, subsequent clicks on the sea use that same address, unless I click further out from the land, in which case it gives me &#8216;no address&#8217;.  Think it&#8217;s an issue with trying to do setContent(&#8221;).  I&#8217;m publishing this article despite it not being quite code-complete, in the hope it helps Frank (and I&#8217;m happy to take suggestions on how to get it fully working as it should).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/duncan99.wordpress.com/1483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/duncan99.wordpress.com/1483/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/duncan99.wordpress.com/1483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/duncan99.wordpress.com/1483/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/duncan99.wordpress.com/1483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/duncan99.wordpress.com/1483/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/duncan99.wordpress.com/1483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/duncan99.wordpress.com/1483/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/duncan99.wordpress.com/1483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/duncan99.wordpress.com/1483/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/duncan99.wordpress.com/1483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/duncan99.wordpress.com/1483/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/duncan99.wordpress.com/1483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/duncan99.wordpress.com/1483/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1483&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://duncan99.wordpress.com/2011/11/04/google-maps-api-adding-infowindows-in-response-to-user-clicks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5594b71e9f54f3e73f6294b054f5616?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">duncan</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/11/google-maps-api-v3-lesson-3-infowindows-in-response-to-user-clicks-mozilla-firefox-03112011-235451.jpg" medium="image">
			<media:title type="html">Google Maps API V3 lesson 3 - infowindows in response to user clicks - Mozilla Firefox 03112011 235451</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/11/google-maps-api-v3-lesson-3-infowindows-in-response-to-user-clicks-mozilla-firefox-04112011-075955.jpg" medium="image">
			<media:title type="html">Google Maps API V3 lesson 3 - infowindows in response to user clicks - Mozilla Firefox 04112011 075955</media:title>
		</media:content>
	</item>
		<item>
		<title>Google Maps API &#8211; infowindows</title>
		<link>http://duncan99.wordpress.com/2011/10/08/google-maps-api-infowindows/</link>
		<comments>http://duncan99.wordpress.com/2011/10/08/google-maps-api-infowindows/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 12:28:21 +0000</pubDate>
		<dc:creator>duncan</dc:creator>
				<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[google map markers]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[google maps api]]></category>
		<category><![CDATA[infowindow]]></category>
		<category><![CDATA[infowindows]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linkedin]]></category>

		<guid isPermaLink="false">http://duncan99.wordpress.com/?p=1455</guid>
		<description><![CDATA[So previously I showed how to create a basic map, then how to add markers to it. Now suppose you&#8217;re wanting to have one of those little bubbles pop up when you click on your map with some information in it. These are called infowindows in Google&#8217;s terminology. Let&#8217;s start with the very basics &#8211; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1455&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So previously I showed <a title="Google Maps API – an introduction" href="http://duncan99.wordpress.com/2011/09/18/google-maps-api-an-introduction/">how to create a basic map</a>, then <a title="Google Maps API – adding markers" href="http://duncan99.wordpress.com/2011/09/25/google-maps-api-adding-markers/">how to add markers to it</a>. Now suppose you&#8217;re wanting to have one of those little bubbles pop up when you click on your map with some information in it. These are called <em>infowindows</em> in Google&#8217;s terminology.</p>
<p>Let&#8217;s start with the very basics &#8211; creating a map which has an infowindow already visible on it.</p>
<pre style="font-size:larger;white-space:pre-wrap;">function initialize() {
	var homeLatlng = new google.maps.LatLng(51.476706,0);

	var myOptions = {
		zoom: 15,
		center: homeLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	var infowindow =  new google.maps.InfoWindow({
		content: 'Hello World!',
		map: map,
		position: homeLatlng
	});
}

google.maps.event.addDomListener(window, 'load', initialize);</pre>
<p><a href="http://duncan99.files.wordpress.com/2011/10/google-maps-api-v3-lesson-1_1317734507450.png"><img src="http://duncan99.files.wordpress.com/2011/10/google-maps-api-v3-lesson-1_1317734507450.png" alt="" title="Google Maps API V3 lesson 1_1317734507450" width="319" height="251" class="aligncenter size-full wp-image-1464" /></a></p>
<p>So we create an infowindow, specify some content for it and which map it&#8217;s for, and give it a latlong position (which coincidentally also happens to be where I&#8217;ve specified this map is to be centered, although that doesn&#8217;t have to be the case).  The <a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#InfoWindow">documentation</a> says that &#8220;<em>After constructing an InfoWindow, you must call open to display it on the map</em>&#8220;; however I find the above code will open the infowindow without needing to explicitly call the <em>open</em> function.</p>
<p>But this shows the infowindow immediately.  Perhaps you&#8217;d rather it only appeared after some user interaction.  Typically you&#8217;d put markers on the map, and when the user clicks the marker, then you&#8217;d show the infowindow.</p>
<p>So let&#8217;s create the infowindow slightly differently.  This time, don&#8217;t specify the <em>position</em> attribute.  Then create a marker as normal, and finally we can open the infowindow, and we pass the marker as the second parameter.  So the infowindow gets anchored to the marker&#8217;s position.</p>
<pre style="font-size:larger;white-space:pre-wrap;">var infowindow =  new google.maps.InfoWindow({
	content: 'Hello World!',
	map: map
});

var marker = new google.maps.Marker({
	position: homeLatlng,
	map: map
});

infowindow.open(map, marker);</pre>
<p><a href="http://duncan99.files.wordpress.com/2011/10/google-maps-api-v3-lesson-1_1317724414567.png"><img class="aligncenter size-full wp-image-1459" title="Google Maps API V3 lesson 1_1317724414567" src="http://duncan99.files.wordpress.com/2011/10/google-maps-api-v3-lesson-1_1317724414567.png" alt="" width="354" height="283" /></a></p>
<p>So we&#8217;ve now added a marker to the map, which the infowindow is then <em>anchored</em> to.</p>
<p>You probably only want this to happen after the user has clicked on that marker. For that we need to have an <em>event listener</em> function. There are many of these available for all the different map elements, in this case we want to listen to the mouseclick event on that marker.</p>
<pre style="font-size:larger;white-space:pre-wrap;">google.maps.event.addListener(marker, 'click', function() {
	infowindow.open(map, this);
});</pre>
<p>So we say to the Google Maps event handler framework, on the marker, listen for any &#8216;click&#8217; events. And when that happens, call this anonymous function which currently only has one line, to open the marker.</p>
<p>We could also make this infowindow appear in response to other events, e.g. if you simply hovered the mouse over the marker.</p>
<pre style="font-size:larger;white-space:pre-wrap;">google.maps.event.addListener(marker, 'mouseover', function() {
	infowindow.open(map, this);
});</pre>
<p>And then to make the infowindow disappear again when you move the mouse away from the marker, just call the <em>close()</em> function on mouseout.</p>
<pre style="font-size:larger;white-space:pre-wrap;">google.maps.event.addListener(marker, 'mouseout', function() {
	infowindow.close();
});</pre>
<p>Suppose you had several markers on your map, each of which would have its own infowindow.  Here&#8217;s one way to deal with that.  Firstly have an array of everything you need for each marker, <em>arrDestinations</em>.  Then loop over them, adding a marker for each.  We only have one infowindow variable, and we just update the content for it in response to user clicks.  We need to delegate the event handler to an external function, <em>bindInfoWindow</em>, otherwise you end up just getting the content of the last array item for each marker.</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;script type="text/javascript"&gt;
function initialize() {
	var i;
	var arrDestinations = [
		{
			lat: 50.815155,
			lon: -0.137072,
			title: "Brighton Pier",
			description: "Brighton Palace Pier dates to 1899"
		},
		{
			lat: 50.822638,
			lon: -0.137361,
			title: "Brighton Pavilion",
			description: "The Pavilion was built for the Prince of Wales in 1787"
		},
		{
			lat: 50.821226,
			lon: -0.139372,
			title: "English's",
			description: "English's Seafood Restaurant and Oyster Bar"
		}
	];

	var myOptions = {
		zoom: 15,
		center: new google.maps.LatLng(50.820645,-0.137376),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	var infowindow =  new google.maps.InfoWindow({
		content: ''
	});

	// loop over our array
	for (i = 0; i &lt; arrDestinations.length; i++) {
		// create a marker
		var marker = new google.maps.Marker({
			title: arrDestinations[i].title,
			position: new google.maps.LatLng(arrDestinations[i].lat, arrDestinations[i].lon),
			map: map
		});

		// add an event listener for this marker
		bindInfoWindow(marker, map, infowindow, &quot;&lt;p&gt;" + arrDestinations[i].description + "&lt;/p&gt;");
	}
}

function bindInfoWindow(marker, map, infowindow, html) {
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.setContent(html);
		infowindow.open(map, marker);
	});
} 

google.maps.event.addDomListener(window, 'load', initialize);
&lt;/script&gt;</pre>
<p><a href="http://duncan99.files.wordpress.com/2011/10/google-maps-api-v3-lesson-1_1318076452057.png"><img src="http://duncan99.files.wordpress.com/2011/10/google-maps-api-v3-lesson-1_1318076452057.png" alt="" title="Google Maps API V3 lesson 1_1318076452057" width="382" height="403" class="aligncenter size-full wp-image-1473" /></a></p>
<p>In production you&#8217;d probably use a server-side language to populate the array and just pass it into the <em>initialize</em> function.  There are other ways of doing this as well.  Another approach is to have multiple infowindows, one for each marker.  On click, you close any open infowindows, and then just open the one that corresponds to the current marker.  I don&#8217;t believe that approach is as efficient as my example though.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/duncan99.wordpress.com/1455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/duncan99.wordpress.com/1455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/duncan99.wordpress.com/1455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/duncan99.wordpress.com/1455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/duncan99.wordpress.com/1455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/duncan99.wordpress.com/1455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/duncan99.wordpress.com/1455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/duncan99.wordpress.com/1455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/duncan99.wordpress.com/1455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/duncan99.wordpress.com/1455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/duncan99.wordpress.com/1455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/duncan99.wordpress.com/1455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/duncan99.wordpress.com/1455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/duncan99.wordpress.com/1455/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1455&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://duncan99.wordpress.com/2011/10/08/google-maps-api-infowindows/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5594b71e9f54f3e73f6294b054f5616?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">duncan</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/10/google-maps-api-v3-lesson-1_1317734507450.png" medium="image">
			<media:title type="html">Google Maps API V3 lesson 1_1317734507450</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/10/google-maps-api-v3-lesson-1_1317724414567.png" medium="image">
			<media:title type="html">Google Maps API V3 lesson 1_1317724414567</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/10/google-maps-api-v3-lesson-1_1318076452057.png" medium="image">
			<media:title type="html">Google Maps API V3 lesson 1_1318076452057</media:title>
		</media:content>
	</item>
		<item>
		<title>Google Maps API &#8211; adding markers</title>
		<link>http://duncan99.wordpress.com/2011/09/25/google-maps-api-adding-markers/</link>
		<comments>http://duncan99.wordpress.com/2011/09/25/google-maps-api-adding-markers/#comments</comments>
		<pubDate>Sun, 25 Sep 2011 12:07:36 +0000</pubDate>
		<dc:creator>duncan</dc:creator>
				<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[google maps api]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[map markers]]></category>
		<category><![CDATA[marker]]></category>
		<category><![CDATA[markerimage]]></category>

		<guid isPermaLink="false">http://duncan99.wordpress.com/?p=1375</guid>
		<description><![CDATA[I previously showed how to create a very simple map. But usually you&#8217;ll want to do more than that. Let&#8217;s start with adding markers to the map. So, using the code from the previous post, I just add this to the end of the initialize function: var homeMarker = new google.maps.Marker({ position: homeLatlng }); That&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1375&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I previously showed <a title="Google Maps API – an introduction" href="http://duncan99.wordpress.com/2011/09/18/google-maps-api-an-introduction/">how to create a very simple map</a>. But usually you&#8217;ll want to do more than that. Let&#8217;s start with adding markers to the map.</p>
<p>So, using the code from the previous post, I just add this to the end of the <em>initialize</em> function:</p>
<pre style="font-size:larger;white-space:pre-wrap;">var homeMarker = new google.maps.Marker({
	position: homeLatlng
});</pre>
<p>That&#8217;s all you need to create a Marker object! There are many other attributes you can specify here, but only <em>position</em> is required.</p>
<p>But you&#8217;ll notice that using this code, no marker will be visible. That&#8217;s because we haven&#8217;t said what map this marker is for. Sometimes you might want to deliberately do this, e.g. by creating markers in advance for showing/hiding dynamically later on.</p>
<p>So there are two ways to associate a marker with a map. When you create the Marker object, just specify the <em>map</em> attribute. The value of which should refer to the variable name you used when you created the Map object.</p>
<pre style="font-size:larger;white-space:pre-wrap;">var homeMarker = new google.maps.Marker({
	position: homeLatlng,
	map: map
});</pre>
<p>Alternatively, you can call the setMap() function:</p>
<pre style="font-size:larger;white-space:pre-wrap;">homeMarker.setMap(map);</pre>
<p>If you ever wanted to remove a marker from a map, just call <em>marker.setMap(null)</em>.</p>
<p>So at this point you&#8217;ve got a map that looks something like this:<br />
<a href="http://duncan99.files.wordpress.com/2011/09/google-maps-api-v3-lesson-2_13165555081261.png"><img class="aligncenter size-full wp-image-1443" title="Google Maps API V3 lesson 2_1316555508126" src="http://duncan99.files.wordpress.com/2011/09/google-maps-api-v3-lesson-2_13165555081261.png" alt="" width="598" height="299" /></a></p>
<p>Great, right? Well maybe you want to do just a bit more than that. Let&#8217;s examine some of the other options.</p>
<p>Firstly, you can specify a title. This will be displayed as a tooltip when you mouse-over the marker.</p>
<pre style="font-size:larger;white-space:pre-wrap;">var homeMarker = new google.maps.Marker({
	position: homeLatlng,
	map: map,
	title: "Check this cool location"
});</pre>
<p><a href="http://duncan99.files.wordpress.com/2011/09/fullscreen-capture-21092011-000333.jpg"><img class="aligncenter size-full wp-image-1389" title="Fullscreen capture 21092011 000333" src="http://duncan99.files.wordpress.com/2011/09/fullscreen-capture-21092011-000333.jpg" alt="" width="599" height="300" /></a></p>
<p>Maybe you&#8217;re not keen on that shadow. Easy, just set the <em>flat</em> property or use the <em>marker.setFlat()</em> function:</p>
<pre style="font-size:larger;white-space:pre-wrap;">var homeMarker = new google.maps.Marker({
	position: homeLatlng,
	map: map,
	title: "Check this cool location",
	flat: true
});</pre>
<p>Perhaps you need users to be able to drag the markers around (this will come in useful later if you&#8217;re doing more advanced dynamic things on the map). Simple, just set the <em>draggable</em> property or use the <em>marker.setDraggable()</em> function:</p>
<pre style="font-size:larger;white-space:pre-wrap;">var homeMarker = new google.maps.Marker({
	position: homeLatlng,
	map: map,
	title: "Check this cool location",
	draggable: true
});</pre>
<p>Fantastic. But supposing you&#8217;re not keen on the default marker image? Not a problem. Google have lots of different marker images you can use:<br />
<img src="http://maps.google.com/mapfiles/ms/micons/purple-dot.png" alt="" /><img src="http://maps.google.com/mapfiles/ms/micons/blue-dot.png" alt="" /><img src="http://maps.google.com/mapfiles/ms/micons/green-dot.png" alt="" /><img src="http://maps.google.com/mapfiles/ms/micons/yellow-dot.png" alt="" /><img src="http://maps.google.com/mapfiles/ms/micons/orange-dot.png" alt="" /><img src="http://maps.google.com/mapfiles/ms/micons/red-dot.png" alt="" /><br />
<img src="http://maps.google.com/mapfiles/ms/micons/purple.png" alt="" /><img src="http://maps.google.com/mapfiles/ms/micons/blue.png" alt="" /><img src="http://maps.google.com/mapfiles/ms/micons/green.png" alt="" /><img src="http://maps.google.com/mapfiles/ms/micons/yellow.png" alt="" /><img src="http://maps.google.com/mapfiles/ms/micons/orange.png" alt="" /><img src="http://maps.google.com/mapfiles/ms/micons/red.png" alt="" /></p>
<p>To use one of these images, just specify the <em>icon</em> property when creating the marker, or use the <em>marker.setIcon()</em> function. You can use either an absolute or relative URL (for images you&#8217;re hosting yourself).</p>
<pre style="font-size:larger;white-space:pre-wrap;">var homeMarker = new google.maps.Marker({
	position: homeLatlng,
	map: map,
	title: "Check this cool location"
	icon: "http://maps.google.com/mapfiles/ms/micons/blue.png"
});</pre>
<p><a href="http://duncan99.files.wordpress.com/2011/09/bluedot1.png"><img class="aligncenter size-full wp-image-1444" title="bluedot" src="http://duncan99.files.wordpress.com/2011/09/bluedot1.png" alt="" width="599" height="300" /></a></p>
<p>One difference you&#8217;ll notice from when we just used the default image, is that no shadow is displayed underneath the marker. You might not care, although it&#8217;s a nice visual touch that gives the map a bit of depth. If you want to specify a shadow, you need to have a shadow image as well. This is the shadow image for the Google markers: <img src="http://maps.google.com/mapfiles/ms/micons/msmarker.shadow.png" alt="" /></p>
<p>One way to setup a shadow is just specify the <em>shadow</em> property on the MarkerOptions, or use <em>marker.setShadow()</em>.</p>
<pre style="font-size:larger;white-space:pre-wrap;">var homeMarker = new google.maps.Marker({
	position: homeLatlng,
	map: map,
	title: "Check this cool location",
	icon: "http://maps.google.com/mapfiles/ms/micons/blue.png",
	shadow: "http://maps.google.com/mapfiles/ms/micons/msmarker.shadow.png"
});</pre>
<p><a href="http://duncan99.files.wordpress.com/2011/09/google-maps-api-v3-lesson-2_1316863627792.png"><img class="alignright size-full wp-image-1424" title="Google Maps API V3 lesson 2_1316863627792" src="http://duncan99.files.wordpress.com/2011/09/google-maps-api-v3-lesson-2_1316863627792.png" alt="" width="110" height="88" /></a>However this doesn&#8217;t actually place the shadow in the correct location for the above example (see image on the right). I think it&#8217;s important to understand what&#8217;s happening here.<br />
The marker image is 32 x 32 pixels in dimensions. The shadow image is also 32 pixels high, but is wider, 59 pixels. Both images are currently being centred horizontally on the same point on the map.</p>
<p>Shadow:<br />
<img class="size-full wp-image-1426 alignnone" title="shadow1" src="http://duncan99.files.wordpress.com/2011/09/shadow1.jpg" alt="" width="80" height="50" /><br />
Marker:<br />
<img class="size-full wp-image-1427 alignnone" title="marker1" src="http://duncan99.files.wordpress.com/2011/09/marker1.jpg" alt="" width="80" height="50" /><br />
Together:<br />
<a href="http://duncan99.files.wordpress.com/2011/09/markershadow.jpg"><img class="size-full wp-image-1428 alignnone" title="markershadow" src="http://duncan99.files.wordpress.com/2011/09/markershadow.jpg" alt="" width="80" height="50" /></a></p>
<p>What we need to do is create MarkerImage objects for both the marker and its shadow, which will allow us to offset the shadow image to be slightly more to the right, so that it lines up nicely with the marker.</p>
<pre style="font-size:larger;white-space:pre-wrap;">var image = new google.maps.MarkerImage(
	'http://maps.google.com/mapfiles/ms/micons/blue-dot.png',
	new google.maps.Size(32, 32),	// size
	new google.maps.Point(0,0),	// origin
	new google.maps.Point(16, 32)	// anchor
);

var shadow = new google.maps.MarkerImage(
	'http://maps.google.com/mapfiles/ms/micons/msmarker.shadow.png',
	new google.maps.Size(59, 32),	// size
	new google.maps.Point(0,0),	// origin
	new google.maps.Point(16, 32)	// anchor
);</pre>
<p>So what&#8217;s going on here? We define the URL of the image, then the size of the image (width,height). Then the origin, which is the x,y coordinates of where our marker starts on that image (useful if you&#8217;re using one sprite image to do lots of markers). The origin locates the top-left corner of our marker. The anchor is the important one here for lining up our marker and our image. This is where the image &#8216;anchors&#8217; itself to our latlng coordinates on the map. So as the marker comes to a point half-way along it, we say it&#8217;s 16 pixels along and 32 points down (i.e. at the bottom of the image). We then repeat this with the shadow, where the tip of the shadow is also 16 pixels along that image, coincidentally.</p>
<p>We then attach the icon and its shadow to the marker like so:</p>
<pre style="font-size:larger;white-space:pre-wrap;">var homeMarker = new google.maps.Marker({
	position: homeLatlng,
	map: map,
	title: "Check this cool location",
	icon: image,
	shadow: shadow
});</pre>
<p><a href="http://duncan99.files.wordpress.com/2011/09/google-maps-api-v3-lesson-2_1316952970485.png"><img class="aligncenter size-full wp-image-1452" title="Google Maps API V3 lesson 2_1316952970485" src="http://duncan99.files.wordpress.com/2011/09/google-maps-api-v3-lesson-2_1316952970485.png" alt="" width="599" height="299" /></a></p>
<p>You can also get markers from other sources, e.g.</p>
<ul>
<li><a href="http://mapicons.nicolasmollet.com/">http://mapicons.nicolasmollet.com/</a></li>
<li><a href="http://mabp.kiev.ua/2010/01/12/google-map-markers/">http://mabp.kiev.ua/2010/01/12/google-map-markers/</a></li>
</ul>
<p>Finally, here&#8217;s the complete code showing how to add custom marker images as outlined above:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Google Maps API V3 lesson 2&lt;/title&gt;

&lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no" /&gt;
&lt;style type="text/css"&gt;
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 300px; width:600px }
&lt;/style&gt;

&lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
	function initialize() {
		var homeLatlng = new google.maps.LatLng(24.696554,-81.328238);

		var myOptions = {
			zoom: 15,
			center: homeLatlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};

		var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

		var image = new google.maps.MarkerImage(
			'http://maps.google.com/mapfiles/ms/micons/green-dot.png',
			new google.maps.Size(32, 32),	// size
			new google.maps.Point(0,0),	// origin
			new google.maps.Point(16, 32)	// anchor
		);

		var shadow = new google.maps.MarkerImage(
			'http://maps.google.com/mapfiles/ms/micons/msmarker.shadow.png',
			new google.maps.Size(59, 32),	// size
			new google.maps.Point(0,0),	// origin
			new google.maps.Point(16, 32)	// anchor
		);

		var homeMarker = new google.maps.Marker({
			position: homeLatlng,
			map: map,
			title: "Check this cool location",
			icon: image,
			shadow: shadow
		});
	}

	google.maps.event.addDomListener(window, 'load', initialize);
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div id="map_canvas"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/duncan99.wordpress.com/1375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/duncan99.wordpress.com/1375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/duncan99.wordpress.com/1375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/duncan99.wordpress.com/1375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/duncan99.wordpress.com/1375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/duncan99.wordpress.com/1375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/duncan99.wordpress.com/1375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/duncan99.wordpress.com/1375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/duncan99.wordpress.com/1375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/duncan99.wordpress.com/1375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/duncan99.wordpress.com/1375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/duncan99.wordpress.com/1375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/duncan99.wordpress.com/1375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/duncan99.wordpress.com/1375/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1375&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://duncan99.wordpress.com/2011/09/25/google-maps-api-adding-markers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5594b71e9f54f3e73f6294b054f5616?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">duncan</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/09/google-maps-api-v3-lesson-2_13165555081261.png" medium="image">
			<media:title type="html">Google Maps API V3 lesson 2_1316555508126</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/09/fullscreen-capture-21092011-000333.jpg" medium="image">
			<media:title type="html">Fullscreen capture 21092011 000333</media:title>
		</media:content>

		<media:content url="http://maps.google.com/mapfiles/ms/micons/purple-dot.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/blue-dot.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/green-dot.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/yellow-dot.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/orange-dot.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/red-dot.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/purple.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/blue.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/green.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/yellow.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/orange.png" medium="image" />

		<media:content url="http://maps.google.com/mapfiles/ms/micons/red.png" medium="image" />

		<media:content url="http://duncan99.files.wordpress.com/2011/09/bluedot1.png" medium="image">
			<media:title type="html">bluedot</media:title>
		</media:content>

		<media:content url="http://maps.google.com/mapfiles/ms/micons/msmarker.shadow.png" medium="image" />

		<media:content url="http://duncan99.files.wordpress.com/2011/09/google-maps-api-v3-lesson-2_1316863627792.png" medium="image">
			<media:title type="html">Google Maps API V3 lesson 2_1316863627792</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/09/shadow1.jpg" medium="image">
			<media:title type="html">shadow1</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/09/marker1.jpg" medium="image">
			<media:title type="html">marker1</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/09/markershadow.jpg" medium="image">
			<media:title type="html">markershadow</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/09/google-maps-api-v3-lesson-2_1316952970485.png" medium="image">
			<media:title type="html">Google Maps API V3 lesson 2_1316952970485</media:title>
		</media:content>
	</item>
		<item>
		<title>ColdFusion LSCurrencyFormat inserts hard spaces?</title>
		<link>http://duncan99.wordpress.com/2011/09/21/coldfusion-lscurrencyformat-inserts-hard-spaces/</link>
		<comments>http://duncan99.wordpress.com/2011/09/21/coldfusion-lscurrencyformat-inserts-hard-spaces/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 20:31:43 +0000</pubDate>
		<dc:creator>duncan</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[assertions]]></category>
		<category><![CDATA[cfml]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[lscurrencyformat]]></category>
		<category><![CDATA[mxunit]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://duncan99.wordpress.com/?p=1393</guid>
		<description><![CDATA[Today I was doing some work with the LSCurrencyFormat function for the very first time. Along the way I discovered something slightly unexpected. If the locale you specify uses spaces for a thousands separator (e.g. French), then Adobe ColdFusion (no idea for Railo or BlueDragon), doesn&#8217;t just add a normal space, it uses a &#8216;hard&#8217; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1393&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I was doing some work with the <a href="http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c1a.html">LSCurrencyFormat</a> function for the very first time.  Along the way I discovered something slightly unexpected.  If the locale you specify uses spaces for a thousands separator (e.g. French), then Adobe ColdFusion (no idea for Railo or BlueDragon), doesn&#8217;t just add a normal space, it uses a &#8216;hard&#8217; space.  </p>
<p>I wouldn&#8217;t have found this out at all if it wasn&#8217;t for the fact I was doing some unit tests with <a href="http://mxunit.org/">MXUnit</a> at the time.  My test case was something like this:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;cfset strPrice = lsCurrencyFormat("12345678.9", "none", "fr_FR")&gt;
&lt;cfset assertEquals("12 345 678,90",  strPrice)&gt;</pre>
<p>So initially that failed, giving me the useful message that<br />
<em>Expected &#8217;12 345 678,90&#8242; but received &#8217;12 345 678,90&#8242;. These values should be the same.</em><br />
Puzzling.  I was doing this in Firefox; if I selected just the error message and then chose View Selection Source, I could see it actually said<br />
<em>Expected &#8217;12 345 678,90&#8242; but received &#8217;12&amp;nbsp;345&amp;nbsp;678,90&#8242;</em>.</p>
<p>Ahah, so I assumed it was inserting the &#8216;&amp;nbsp;&#8217; <a href="http://en.wikipedia.org/wiki/Non-breaking_space">non-breaking space</a> HTML entity into the value instead of just a normal single space.  So I updated my unit test assertion to be like this:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;cfset assertEquals("12&amp;nbsp;345&amp;nbsp;678,90",  strPrice)&gt;</pre>
<p>But that also failed, and this time when checking the source, it said<br />
<em>Expected &#8217;12&amp;nbsp;345&amp;nbsp;678,90&#8242; but received &#8217;12&amp;nbsp;345&amp;nbsp;678,90&#8242;</em>.<br />
Curiouser and curiouser!</p>
<p>So at this point, I decided to loop over the actual string returned by lsCurrencyFormat to examine it more closely:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;cfoutput&gt;
	&lt;cfset french = lsCurrencyFormat("12345678.90", "none", "fr_FR")&gt;

	&lt;cfloop index="i" from="1" to="#Len(french)#"&gt;
		&lt;cfset char = mid(french, i, 1)&gt;

		#char#:#Asc(char)#&lt;br/&gt;
	&lt;/cfloop&gt;
&lt;/cfoutput&gt;</pre>
<p>Which produced output that looked like:</p>
<pre style="font-size:larger;white-space:pre-wrap;">1:49
2:50
 :160
3:51
4:52
5:53
 :160
6:54
7:55
8:56
,:44
9:57
0:48</pre>
<p>The normal HTML space is ASCII character 32.  But in this case it&#8217;s inserting ASCII character 160, which the browser interprets as &amp;nbsp;.  So for my unit test to work, I&#8217;ll have to do something like:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;cfset assertEquals("12" &amp; Chr(160) &amp; "345" &amp; Chr(160) &amp; "678,90",  strPrice)&gt;</pre>
<p><del datetime="2011-09-22T16:47:53+00:00">Dunno why Adobe in their infinite wisdom (to be honest this probably dates back to Allaire or Macromedia) would use character 160 instead just a normal single space character 32.  And I expect other locale-specific formatting functions must do the same thing.</del><br />
I&#8217;m getting exactly the same results with <strong>java.text.DecimalFormatSymbols.getGroupingSeparator()</strong>, so I expect ColdFusion is using that functionality in the background.</p>
<p>I suppose it shouldn&#8217;t really cause any problems, apart from perhaps when you&#8217;re needing to unit test (or perhaps if parsing some HTML you&#8217;ve received by CFHTTP).  Just, unexpected is all.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/duncan99.wordpress.com/1393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/duncan99.wordpress.com/1393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/duncan99.wordpress.com/1393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/duncan99.wordpress.com/1393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/duncan99.wordpress.com/1393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/duncan99.wordpress.com/1393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/duncan99.wordpress.com/1393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/duncan99.wordpress.com/1393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/duncan99.wordpress.com/1393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/duncan99.wordpress.com/1393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/duncan99.wordpress.com/1393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/duncan99.wordpress.com/1393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/duncan99.wordpress.com/1393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/duncan99.wordpress.com/1393/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1393&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://duncan99.wordpress.com/2011/09/21/coldfusion-lscurrencyformat-inserts-hard-spaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5594b71e9f54f3e73f6294b054f5616?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">duncan</media:title>
		</media:content>
	</item>
		<item>
		<title>Adobe survey</title>
		<link>http://duncan99.wordpress.com/2011/09/19/adobe-survey/</link>
		<comments>http://duncan99.wordpress.com/2011/09/19/adobe-survey/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 18:57:42 +0000</pubDate>
		<dc:creator>duncan</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA["hansa research"]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[marquee]]></category>

		<guid isPermaLink="false">http://duncan99.wordpress.com/?p=1378</guid>
		<description><![CDATA[I was sent a link to a survey on behalf of Adobe, asking about use of ColdFusion. The website the survey is on doesn&#8217;t get off to a promising start: uh, ok. So I proceed to the next page, which made me swear out loud. Yes, that&#8217;s right, that bit in the blue text at [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1378&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was sent a link to a <a href="http://www.hansaresearch.com/coldplay/">survey on behalf of Adobe</a>, asking about use of ColdFusion.  The website the survey is on doesn&#8217;t get off to a promising start:<br />
<a href="http://duncan99.files.wordpress.com/2011/09/adobe-coldfusion-mozilla-firefox-19092011-193125.jpg"><img src="http://duncan99.files.wordpress.com/2011/09/adobe-coldfusion-mozilla-firefox-19092011-193125.jpg" alt="" title="Adobe ColdFusion - Mozilla Firefox 19092011 193125" width="623" height="149" class="aligncenter size-full wp-image-1379" /></a></p>
<p>uh, ok.  So I proceed to the next page, which made me swear out loud.<br />
<a href="http://duncan99.files.wordpress.com/2011/09/adobe-coldfusion_1316457471688.png"><img src="http://duncan99.files.wordpress.com/2011/09/adobe-coldfusion_1316457471688.png" alt="" title="Adobe ColdFusion_1316457471688" width="650" height="448" class="aligncenter size-full wp-image-1380" /></a></p>
<p>Yes, that&#8217;s right, that bit in the blue text at the bottom, scrolling along the page, it&#8217;s the &lt;marquee&gt; tag in use!  And not even ironically.  It&#8217;s like 1999 all over again&#8230;</p>
<pre style="font-size:larger;white-space:pre-wrap;">
&lt;p&gt;&lt;span class="style1"&gt;
  &lt;marquee&gt;
  This survey is best viewed with Internet Explorer
  &lt;/marquee&gt;
&lt;/span&gt;&lt;/p&gt;</pre>
<p>I ended up giving up on it fairly quickly after that.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/duncan99.wordpress.com/1378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/duncan99.wordpress.com/1378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/duncan99.wordpress.com/1378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/duncan99.wordpress.com/1378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/duncan99.wordpress.com/1378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/duncan99.wordpress.com/1378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/duncan99.wordpress.com/1378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/duncan99.wordpress.com/1378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/duncan99.wordpress.com/1378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/duncan99.wordpress.com/1378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/duncan99.wordpress.com/1378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/duncan99.wordpress.com/1378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/duncan99.wordpress.com/1378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/duncan99.wordpress.com/1378/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1378&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://duncan99.wordpress.com/2011/09/19/adobe-survey/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5594b71e9f54f3e73f6294b054f5616?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">duncan</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/09/adobe-coldfusion-mozilla-firefox-19092011-193125.jpg" medium="image">
			<media:title type="html">Adobe ColdFusion - Mozilla Firefox 19092011 193125</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/09/adobe-coldfusion_1316457471688.png" medium="image">
			<media:title type="html">Adobe ColdFusion_1316457471688</media:title>
		</media:content>
	</item>
		<item>
		<title>Google Maps API &#8211; an introduction</title>
		<link>http://duncan99.wordpress.com/2011/09/18/google-maps-api-an-introduction/</link>
		<comments>http://duncan99.wordpress.com/2011/09/18/google-maps-api-an-introduction/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 09:35:35 +0000</pubDate>
		<dc:creator>duncan</dc:creator>
				<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[google maps api]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[latitude and longitude]]></category>
		<category><![CDATA[latitude and longitude coordinates]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[maps]]></category>

		<guid isPermaLink="false">http://duncan99.wordpress.com/?p=1325</guid>
		<description><![CDATA[This is the first in a series of posts I intend to do looking into some uses of the Google Maps Javascript API, V3. Let&#8217;s start at the very beginning &#8211; you want to display a map on a webpage, so what&#8217;s required. This is the bare minimum you need to do. Add an empty [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1325&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the first in a series of posts I intend to do looking into some uses of the <a href="http://code.google.com/apis/maps/documentation/javascript/">Google Maps Javascript API, V3</a>. Let&#8217;s start at the very beginning &#8211; you want to display a map on a webpage, so what&#8217;s required. This is the bare minimum you need to do.</p>
<p>Add an empty &lt;div&gt; to your HTML page, with a suitable ID attribute:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;div id="map_canvas"&gt;&lt;/div&gt;</pre>
<p>Add some CSS like this:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;style type="text/css"&gt;
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
&lt;/style&gt;</pre>
<p>Include the Google Maps javascript file:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;</pre>
<p>Create a javascript function that includes all the next few lines of code; let&#8217;s stick to convention and call it <em>initialize</em>.</p>
<p>Create a latlong object which indicates the <a href="http://en.wikipedia.org/wiki/Latitude">latitude</a> and <a href="http://en.wikipedia.org/wiki/Longitude">longitude</a> where your map is centred:</p>
<pre style="font-size:larger;white-space:pre-wrap;">var homeLatlng = new google.maps.LatLng(51.42838,0.0); // London</pre>
<p>If you don&#8217;t already know the latitude and longitude for where you want to place your map, there&#8217;s a very easy way to find out:</p>
<ol>
<li>Go to <a href="http://maps.google.com/">Google Maps</a></li>
<li>Search for your desired destination, and zoom right in</li>
<li>Right-click on the map at your destination, and choose the <em>&#8220;What&#8217;s here?&#8221;</em> option</li>
<li>The latitude and longitude coordinates will appear in the search box</li>
</ol>
<p><a href="http://duncan99.files.wordpress.com/2011/09/40-771994-73-974552-google-maps-mozilla-firefox-18092011-090653.jpg"><img class="aligncenter size-medium wp-image-1351" src="http://duncan99.files.wordpress.com/2011/09/40-771994-73-974552-google-maps-mozilla-firefox-18092011-090653.jpg" alt="" /></a></p>
<p>Create a structure with the following properties:</p>
<pre style="font-size:larger;white-space:pre-wrap;">var myOptions = {
	zoom: 10,
	center: homeLatlng,
	mapTypeId: google.maps.MapTypeId.ROADMAP
};</pre>
<p>The zoom value can be any integer between 0 (fully zoomed out) and about 18. Some cities will support zoom up to about 20, and there are isolated cases of parts of maps having a zoom level up to 23 or more! In general though you won&#8217;t want to zoom in that far. Typically I&#8217;d set this around 7 &#8211; 15 depending on what kind of map I&#8217;m displaying.</p>
<p>The center value uses the latlong object you already created.</p>
<p>The mapTypeId value can be one of four options:</p>
<ol>
<li>google.maps.MapTypeId.ROADMAP &#8211; normal street map</li>
<li>google.maps.MapTypeId.SATELLITE &#8211; satellite photos (might not be available for all locations if you&#8217;re zoomed in too far)</li>
<li>google.maps.MapTypeId.HYBRID &#8211; combination of a satellite map with streets overlaid on top</li>
<li>google.maps.MapTypeId.TERRAIN &#8211; what it sounds like, indicates natural features, height of land etc</li>
</ol>
<p>I generally stick with ROADMAP, as that&#8217;s the most typical map type you see by default. Here&#8217;s a demonstration of the different types:<br />
<a href="http://duncan99.files.wordpress.com/2011/09/1316335834132.jpg"><img src="http://duncan99.files.wordpress.com/2011/09/1316335834132.jpg" alt="" title="Truth or Consequences maps" width="500" height="1326" class="aligncenter size-full wp-image-1363" /></a></p>
<p>Create a new map with the structure of options you just created, and specifying the DIV where you want the map to appear:</p>
<pre style="font-size:larger;white-space:pre-wrap;">var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);</pre>
<p>That&#8217;s the end of your <em>initialize</em> function.  You could just call this using the onload attribute of the body tag. Or if you were using jQuery, with $(document).ready(). However, Google has an event listener, that does the same thing:</p>
<pre style="font-size:larger;white-space:pre-wrap;">google.maps.event.addDomListener(window, 'load', initialize);</pre>
<p>Wrapping it all up, here&#8217;s the complete page for simply displaying a map at a given location:</p>
<pre style="font-size:larger;white-space:pre-wrap;">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Google Maps API V3 lesson 1&lt;/title&gt;

&lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no" /&gt;
&lt;style type="text/css"&gt;
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
&lt;/style&gt;

&lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
	function initialize() {
		var homeLatlng = new google.maps.LatLng(51.476706,0); // London

		var myOptions = {
			zoom: 15,
			center: homeLatlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};

		var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	}

	google.maps.event.addDomListener(window, 'load', initialize);
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div id="map_canvas"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/duncan99.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/duncan99.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/duncan99.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/duncan99.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/duncan99.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/duncan99.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/duncan99.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/duncan99.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/duncan99.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/duncan99.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/duncan99.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/duncan99.wordpress.com/1325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/duncan99.wordpress.com/1325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/duncan99.wordpress.com/1325/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1325&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://duncan99.wordpress.com/2011/09/18/google-maps-api-an-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5594b71e9f54f3e73f6294b054f5616?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">duncan</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2011/09/40-771994-73-974552-google-maps-mozilla-firefox-18092011-090653.jpg" medium="image" />

		<media:content url="http://duncan99.files.wordpress.com/2011/09/1316335834132.jpg" medium="image">
			<media:title type="html">Truth or Consequences maps</media:title>
		</media:content>
	</item>
		<item>
		<title>Using jQuery to animate table rows</title>
		<link>http://duncan99.wordpress.com/2011/09/17/using-jquery-to-animate-table-rows/</link>
		<comments>http://duncan99.wordpress.com/2011/09/17/using-jquery-to-animate-table-rows/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 08:00:31 +0000</pubDate>
		<dc:creator>duncan</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://duncan99.wordpress.com/?p=1334</guid>
		<description><![CDATA[jQuery has some nice ways to animate content, e.g. sliding or fading it into view. These don&#8217;t really work on &#60;tr&#62; or &#60;td&#62; tags though. I had a situation recently where we wanted to add an extra &#60;tr&#62; into a table, and make it slide in. The answer&#8217;s very simple (thanks to stackoverflow) &#8211; wrap [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1334&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>jQuery has some nice ways to animate content, e.g. sliding or fading it into view.  These don&#8217;t really work on &lt;tr&gt; or &lt;td&gt; tags though.  I had a situation recently where we wanted to add an extra &lt;tr&gt; into a table, and make it slide in.  The answer&#8217;s very simple (thanks to <a href="http://stackoverflow.com/questions/467336/jquery-how-to-use-slidedown-or-show-function-on-a-table-row" title="stackoverflow">stackoverflow</a>) &#8211; wrap the table content in a div, and add the slide animation to that instead.</p>
<p>So imagine you have a very simple example table like this:</p>
<pre style="font-size:larger;white-space:pre-wrap;">
&lt;table&gt;
	&lt;tr id="row1"&gt;
		&lt;td&gt;&lt;a href=""&gt;Show another row&lt;/a&gt;&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
</pre>
<p>This javascript would then make the second &lt;tr&gt; slide into view.</p>
<pre style="font-size:larger;white-space:pre-wrap;">
&lt;script type="text/javascript"&gt;
$(document).ready(function() {
	// hidden content to add after the current row
	$('#row1').after("&lt;tr id='row2'&gt;&lt;td&gt;&lt;div style='display:none'&gt;There's a voice that keeps on calling me. Down the road, that's where I'll always be. Every stop I make, I make a new friend. Can't stay for long, just turn around and I'm gone again. Maybe tomorrow, I'll want to settle down, Until tomorrow, I'll just keep moving on.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;");

	$('#row1 a').click(function() {
		if ($('#row2 div').is(":visible")) {
			// hide the div
			$('#row2 div').slideUp(700);

		} else {
			// slide the div into view
			$('#row2 div').slideDown(700);
		}

		// prevent the click on the link from propagating
		return false;
	});
});
&lt;/script&gt;
</pre>
<p>Of course it gets more complicated if you have more than one &lt;td&gt;. For example:</p>
<pre style="font-size:larger;">
&lt;table&gt;
	&lt;tr id="row1"&gt;
		&lt;td&gt;A&lt;/td&gt;
		&lt;td&gt;One&lt;/td&gt;
		&lt;td&gt;Red&lt;/td&gt;
		&lt;td&gt;Apple&lt;/td&gt;
		&lt;td&gt;$0.99&lt;/td&gt;
		&lt;td&gt;&lt;a href=""&gt;Show row 2&lt;/a&gt;&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
</pre>
<p>In that case you can use the <a href="http://api.jquery.com/wrapInner/" title=".wrapInner">.wrapInner</a> function to add a hidden div to all the &lt;td&gt; tags.</p>
<pre style="font-size:larger;">
&lt;script type="text/javascript"&gt;
$(document).ready(function() {
	// content to add after the current row
	var $row2 =	$('&lt;tr id="row2"&gt;' +
					'&lt;td&gt;B&lt;/td&gt;' +
					'&lt;td&gt;Two&lt;/td&gt;' +
					'&lt;td&gt;Yellow&lt;/td&gt;' +
					'&lt;td&gt;Banana&lt;/td&gt;' +
					'&lt;td&gt;$1.23&lt;/td&gt;' +
					'&lt;td&gt;&nbsp;&lt;/td&gt;' +
				'&lt;/tr&gt;');

	// add hidden divs around the content of all the TD tags
	$row2.find('td').wrapInner('&lt;div style="display:none" /&gt;');

	// add this row after the first row
	$('#row1').after($row2);

	$('#row1 a').click(function() {
		if ($('#row2 div').is(":visible")) {
			// hide the div
			$('#row2 div').slideUp(700);

			// update link text
			$('#row1 a').text('show row 2');

		} else {
			// slide the div into view
			$('#row2 div').slideDown(700);

			// update link text
			$('#row1 a').text('hide row 2');
		}

		// prevent the click on the link from propagating
		return false;
	});
});
&lt;/script&gt;
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/duncan99.wordpress.com/1334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/duncan99.wordpress.com/1334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/duncan99.wordpress.com/1334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/duncan99.wordpress.com/1334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/duncan99.wordpress.com/1334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/duncan99.wordpress.com/1334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/duncan99.wordpress.com/1334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/duncan99.wordpress.com/1334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/duncan99.wordpress.com/1334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/duncan99.wordpress.com/1334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/duncan99.wordpress.com/1334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/duncan99.wordpress.com/1334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/duncan99.wordpress.com/1334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/duncan99.wordpress.com/1334/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1334&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://duncan99.wordpress.com/2011/09/17/using-jquery-to-animate-table-rows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5594b71e9f54f3e73f6294b054f5616?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">duncan</media:title>
		</media:content>
	</item>
		<item>
		<title>Project Euler problem 26</title>
		<link>http://duncan99.wordpress.com/2011/06/19/project-euler-problem-26/</link>
		<comments>http://duncan99.wordpress.com/2011/06/19/project-euler-problem-26/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 21:27:44 +0000</pubDate>
		<dc:creator>duncan</dc:creator>
				<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://duncan99.wordpress.com/?p=1306</guid>
		<description><![CDATA[Problem 26: A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given: 1/2 = 0.5 1/3 = 0.(3) 1/4 = 0.25 1/5 = 0.2 1/6 = 0.1(6) 1/7 = 0.(142857) 1/8 = 0.125 1/9 = 0.(1) 1/10 = 0.1 Where 0.1(6) means 0.166666&#8230;, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1306&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://projecteuler.net/index.php?section=problems&amp;id=26" title="Problem 26">Problem 26</a>:</p>
<blockquote><p><em>A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:</p>
<p>    1/2	= 	0.5<br />
    1/3	= 	0.(3)<br />
    1/4	= 	0.25<br />
    1/5	= 	0.2<br />
    1/6	= 	0.1(6)<br />
    1/7	= 	0.(142857)<br />
    1/8	= 	0.125<br />
    1/9	= 	0.(1)<br />
    1/10	= 	0.1</p>
<p>Where 0.1(6) means 0.166666&#8230;, and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.</p>
<p>Find the value of d &lt; 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.</em>
</p></blockquote>
<p>Another one I initially attempted with ColdFusion, but it didn&#8217;t give decimals to enough precision (at least without using the underlying Java), so turned to Python.  </p>
<p>To me this seemed like a good place to use a regular expression, where you can match a group and any repetitions of it, using back-references.  Some problems around which parts should be greedy or not.  For instance if you have 0.01010101  is the repeating pattern 0101 twice, or 01 four times?</p>
<p>Here&#8217;s the regular expression I used:</p>
<p>&#8220;^0\.[0-9]*([0-9]{7,}?)\1+[0-9]*?$&#8221;</p>
<p>And here&#8217;s an explanation of the various parts of it:</p>
<p><strong>^</strong>0\.[0-9]*([0-9]{7,}?)\1+[0-9]*?<strong>$</strong></p>
<p>The ^ matches the beginning of the string, and the $ matches the end of the string.  They&#8217;re not always strictly necessary, but it can be good practice for examples like this.</p>
<p>^<strong>0\.</strong>[0-9]*([0-9]{7,}?)\1+[0-9]*?$</p>
<p>The value is 1/d.  As d starts at 2 and increases to 1000, the value starts at 0.5 and gets closer and closer to zero.  So the value is always going to start with a zero.  Normally a . in a regular expression indicates &#8216;any character&#8217;.  The \. just tells the regular expression engine to &#8216;escape&#8217; it and treat it as a string literal, not a regex special character.</p>
<p>^0\.<strong>[0-9]*</strong>([0-9]{7,}?)\1+[0-9]*?$</p>
<p>[0-9] just means match any digit between 0 and 9.  The * means 0 or many.  Notice this is before the part in the ( ) that I&#8217;m really interested in.  So in other words, there may be some digits before the pattern.  e.g. for 1/6, which is 0.166666&#8230; I don&#8217;t care about that first digit 1.</p>
<p>^0\.[0-9]*<strong>([0-9]{7,}?)</strong>\1+[0-9]*?$</p>
<p>The ( ) is a way of grouping parts of a regex, in this case for the benefit of back-referencing.<br />
The fact we&#8217;re given a 6 digit example means we can assume the answer has to be at least 7 digits.  So I used the {7,} syntax to mean the group has to be a minimum of 7 digits long.<br />
The ? means 0 or 1.  In other words, only give me up to 1 matching group that is a minimum of 7 characters long, and don&#8217;t be greedy!</p>
<p>^0\.[0-9]*([0-9]{7,}?)<strong>\1+</strong>[0-9]*?$</p>
<p>The \1 is a back reference to the earlier grouped part.  If there were multiple parts each with their own ( ) you could back-reference them with \2, \3 etc.<br />
And the + means 1 or more, so there has to be at least 1 repeating group.</p>
<p>^0\.[0-9]*([0-9]{7,}?)\1+<strong>[0-9]*?</strong>$</p>
<p>The final [0-9] is for any trailing digits that don&#8217;t fit the pattern.  Even though once the pattern starts in theory it continues infinitely, in reality you might get a value that is rounded,  e.g. where you have 0.16666667 instead of 0.16666666&#8230;<br />
The * means zero or many of these trailing digits, and the ? stops it from being greedy.  Interestingly, you&#8217;d assume that just the ? on its own would be more efficient, as that extra digit is just going to be one optional digit and no more.  But that reduces the performance somewhat.  </p>
<p>And here&#8217;s the complete code.</p>
<pre style="font-size:larger;">
import re
from decimal import *

def displaymatch(match):
    if match is None:
        return 0

    return len(match.group(1))

length = 0
maxlen = 0
d = 0
getcontext().prec = 2000

for i in range(1,1000):
    fraction = 1/Decimal(i)
    pattern = re.search(r"^[0-9]\.[0-9]*([0-9]{7,}?)(\1+)[0-9]*?$", str(fraction))

    length = displaymatch(pattern)

    if length &gt; maxlen:
        maxlen = length
        d = i

print(d)</pre>
<p>I&#8217;m using the Python regular expression and Decimal libraries.  I also had to increase the precision of the decimal context to up to 2000, as lower values were giving me incorrect answers.  i.e. it was truncating the fraction a bit, which meant my pattern matching wasn&#8217;t finding the correct answer.  So by increasing the precision, I increased the length of the fraction being returned, and therefore improved the chances of finding the correct answer.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/duncan99.wordpress.com/1306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/duncan99.wordpress.com/1306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/duncan99.wordpress.com/1306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/duncan99.wordpress.com/1306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/duncan99.wordpress.com/1306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/duncan99.wordpress.com/1306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/duncan99.wordpress.com/1306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/duncan99.wordpress.com/1306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/duncan99.wordpress.com/1306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/duncan99.wordpress.com/1306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/duncan99.wordpress.com/1306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/duncan99.wordpress.com/1306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/duncan99.wordpress.com/1306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/duncan99.wordpress.com/1306/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1306&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://duncan99.wordpress.com/2011/06/19/project-euler-problem-26/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5594b71e9f54f3e73f6294b054f5616?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">duncan</media:title>
		</media:content>
	</item>
		<item>
		<title>cfdump label attribute</title>
		<link>http://duncan99.wordpress.com/2010/09/16/cfdump-label-attribute/</link>
		<comments>http://duncan99.wordpress.com/2010/09/16/cfdump-label-attribute/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 21:06:32 +0000</pubDate>
		<dc:creator>duncan</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[cfdump]]></category>
		<category><![CDATA[cfml]]></category>

		<guid isPermaLink="false">http://duncan99.wordpress.com/?p=1286</guid>
		<description><![CDATA[The &#60;cfdump&#62; tag in ColdFusion has an optional label attribute which doesn&#8217;t seem to be commonly used. Sometimes if you&#8217;re dumping out several items at the same time, and potentially from separate files, it can be handy to identify the source of each one. However I just noticed that the label seems to get applied [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1286&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <strong>&lt;cfdump&gt;</strong> tag in ColdFusion has an optional <strong>label</strong> attribute which doesn&#8217;t seem to be commonly used.  Sometimes if you&#8217;re dumping out several items at the same time, and potentially from separate files, it can be handy to identify the source of each one.</p>
<p>However I just noticed that the label seems to get applied to <strong>all</strong> complex data structures within the dumped variable.  For example this code:</p>
<pre style="font-size:larger;">
&lt;cfset a.b.x = {a='one', b='two', c='three'}&gt;
&lt;cfset a.b.y = [1,2,3]&gt;
&lt;cfset a.b.z = 7&gt;
&lt;cfdump var="#a#" label="my struct"&gt;
</pre>
<p>Produces this output:</p>
<p><img class="size-full wp-image-1292 alignnone" title="cfdump" src="http://duncan99.files.wordpress.com/2010/09/cfdump.png" alt="" width="177" height="279" /></p>
<p>No big deal, just something I&#8217;d noticed.  I guess ColdFusion recursively applies the label to all structures as it dumps them out.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/duncan99.wordpress.com/1286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/duncan99.wordpress.com/1286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/duncan99.wordpress.com/1286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/duncan99.wordpress.com/1286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/duncan99.wordpress.com/1286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/duncan99.wordpress.com/1286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/duncan99.wordpress.com/1286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/duncan99.wordpress.com/1286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/duncan99.wordpress.com/1286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/duncan99.wordpress.com/1286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/duncan99.wordpress.com/1286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/duncan99.wordpress.com/1286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/duncan99.wordpress.com/1286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/duncan99.wordpress.com/1286/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=duncan99.wordpress.com&amp;blog=4274552&amp;post=1286&amp;subd=duncan99&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://duncan99.wordpress.com/2010/09/16/cfdump-label-attribute/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5594b71e9f54f3e73f6294b054f5616?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">duncan</media:title>
		</media:content>

		<media:content url="http://duncan99.files.wordpress.com/2010/09/cfdump.png" medium="image">
			<media:title type="html">cfdump</media:title>
		</media:content>
	</item>
	</channel>
</rss>
