A web developing, photo taking, Muay Thai fighting man.

Using the MultiMap Geocoding API With Coldfusion (Railo) to Encode UK Postcodes

Posted: March 16th, 2009 | Author: James | Filed under: Web Development | Tags: , , , , | No Comments »

At the moment I’m working on a project at the moment that requires the encoding of UK postcodes to latitude and longitude for doing spatial searches on some local data.  Multimap provide a REST API for doing just that and I’d been reliably informed that it was a bit more accurate than the Yahoo and Google equivalents (which mainly fall down in rural areas – of which there are plenty in Scotland).

The predominant way of consuming a REST api in CFML is through the CFHTTP tag which allows you to easily perform HTTP requests.  Unfortunately, CFHTTP didn’t work straight away for me with the Multimap API – giving the following error.

MM_API_UNSUPPORTED_REQUEST_TYPE

Whenever I tried to perform even the most simple of queries.  Requesting the exact same URL in my browser worked without a problem.

After searching Google to no avail the only other option I had was to inspect the raw HTTP request.

It seems that the Multimap API was fallign over due to the Content-type header generated by Axis.  More specifically it was the charset option that was causing it to fail.

Content-Type: application/x-www-form-urlencoded; charset=UTF-8

Easily remedied by adding a CFHTTPPARAM for a new header with the charset omitted from the value.

<cfhttp url="http://developer.multimap.com/API/geocode/1.2/[api_key]?qs=EC4A2DY">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />
</cfhttp>

I’m not sure if this is a bug with the version of Railo I was using (tried on 3.0.1 and 3.0.2) or related to the Axis2 java libraries that Railo uses to implement CFHTTP.  I’m yet to try it on the Adobe Coldfusion server.