Shaun Mccran

My digital playground


Integrating Google search into your site using ColdFusion and XML

Rather than writing a custom search, and indexing service for your sites you can use Google to do the leg work for you.

This article examines how you can create and integrate a Google site search into your site. We will query Google and return an XML packet, which we will translate and display within our sites framework.

[ More ]


Tracking single page sites with Google analytics code

If you have a framework that controls the URL in some way then you may have an issue when it comes to Google Analytics tracking. In this blog entry I will examine how to alter your GA tracking so that you can specify custom URL values to track. I will then apply this to a FuseBox framework.

Traditionally Google Analytics code tracks each page impression by capturing the URL and all values of the Query string, storing it in a cookie and sending it back to the Google search engine through a JavaScript call. When all your site / applications pages are "index.cfm" it may prove difficult to generate useful Analytics information.

In this example I am using a FuseBox framework. If you are unfamiliar with this, the premise is that all the templates use "index.cfm" and then pass through two parameters. The first is the component to use as a controller (we will use public.cfc) and the second value is the function name to call within that controller. So our URL may look like this:

view plain print about

[ More ]


Firefox not displaying Google maps generated images

My latest Google maps lookup template was not working in Firefox 3.n. It was working fine in IE 8 (and 8) so I thought maybe IE was compensating for some shaky JavaScript code, and 'working out' what I was trying to do and fixing it for me.

After spending half an hour painstaking going through my Google JavaScript and removing everything out of my FuseBox framework, just in case anything was mysteriously interfering, I was at a dead end.

A quick flick around online and it seems that there is a setting in FireFox that blocks this sort of functionality.

  1. Type 'about:config' (without quotes) in the browser's address bar.
  2. Type 'image' (without quotes) in the 'Filter' field.
  3. Verify that 'dom.disable_image_src_set' is set to FALSE.
  4. Verify that 'permissions.default.image' is set to 0 (the default setting).

FireFox settings about:config

For some reason in my FireFox installation the 'permissions.default.image' was set to 1, which blocks the function return from Google.

Google has a tech note on it here:

It is really frustrating when 'controls' are set outside of the development environment. Now to put all my code back!


Geo coding Latitude and Longitude address in coldfusion using CFhttp

One piece of recently functionality to a site I'm writing is the ability to look up places on a Google powered map.

There are a variety of ways to insert a Google map into your site, but the first real hurdle is the lookup code.

Google does not use an address to position its map, it uses the Latitude and Longitude co-ordinates to place the map area around the desired location.

Google has pretty extensive documentation around this here:

Rather than translate the locations on the fly on a per-hit basis I thought I would perform the lookup when the record is submitted to the database, that way I can cut down the number of google hits, and just reference the local data. Google also prefers this method, as it is less process intensive on their end of things.

First you need an API key:

This application already has methods for setting the data in a table, so I am simply going to call another packaged method to calculate the latitude and longitude, and store them in the table with the other data.

view plain print about
1<cffunction name="fetchGeo" displayname="fetch Geo" hint="Gets the Geo lat long for an address: docs at" access="public" output="false" returntype="struct">
2        <cfargument name="address" displayName="Address to Geo" type="string" hint="String of the address to Geo code" required="true" />
3        <cfset var geoDetails = structNew()>
5        <cfset var apiKey = "Your API key here">
7        <!--- initial string --->
8        <cfset var requestString = "">
10        <!--- q= address to geo code --->
11        <cfset requestString = requestString & "q=28+Morley+Street,Swindon,SN1+1SG" & "&">
13        <!--- key = API key --->
14        <cfset requestString = requestString & "key=" & apiKey & "&">
16        <!--- sensor = does the requestor have a location sensor? --->
17        <cfset requestString = requestString & "sensor=false" & "&">
19        <!--- output = output format --->
20        <cfset requestString = requestString & "output=csv" & "&">
22        <!--- oe = output encoding format --->
23        <cfset requestString = requestString & "oe=utf8" & "&">
25        <!--- gl= Country code pointer --->
26        <cfset requestString = requestString & "gl=uk">
28        <cfhttp url="#requestString#" method="get" result="response"></cfhttp>
30        <!--- returns 4 elements statuscode/accuracy/lat/long
31             Higher accuracy is better --->

32        <cfset geoDetails.status = listGetAt(response.filecontent,'1',',')>
33        <cfset geoDetails.accuracy = listGetAt(response.filecontent,'2',',')>
34        <cfset = listGetAt(response.filecontent,'3',',')>
35        <cfset geoDetails.long = listGetAt(response.filecontent,'4',',')>
37        <cfreturn geoDetails />
38    </cffunction>

As you can see from above, I am simply creating a text string URL, and using cfhttp to GET the result from

The screenshot below show the returned responses, and the http status code.

The result is parsed into a struct and returned to the parent function to be stored. Far less overhead than doing this for every map call.

Please note that this is far more heavily commented for Blog purposes. Now to actually call the service using the lat and long variables stored, but thats another article.