Skip to main content

Using Google Maps Places API and ColdFusion's CFMAP to render places of interests

Google announced the Places API recently at Google I/O (2011) and I was looking into this, to see how this API can be used in conjunction with ColdFusion maps created with CFMAP. The Places API can be used to retrieve place information which includes:
  • Places of interests such as parks, restaurants, hospitals which are nearby to the users location.
  • More detailed information on the place, such as the address, phone number etc,.
The API can also be used to perform check-in at a particular place and to add\delete a place. These check-ins can then be used to evaluate the popularity of the place. In this post I'll explain how to retrieve the places of interests and displaying the same on a ColdFusion map using CFMAP.

Place Search Requests - retrieving the places of interests near a user's location:
You can send a HTTP request to the URL of the form:

Here the user has an option of specifying the output format as either json or xml and is required to pass a few parameters:
  • key (required): The application's API key. The Places API uses this information to identify your application.
  • location (required): This will be the latitude and longitude information of a particular place around which the places of interests are to be found.
  • radius (required): to specify the radius within which the places of interests are to be found. The value specified will be considered in meters.
  • sensor (required): to indicate whether the place request is from a device using the location sensor. It can be either true or false.
  • types (optional): the user might be interested in various types of businesses such as library, park, gym etc,. You can also specify multiple types which are separated by a '|' (type1|type2|type3).
  • name (optional): A term to be matched against the names of places. This will restrict the results to contain only those with the specified name.
  • language (optional): The language code to indicate the language in which the results are to be returned. 
With the above information, you can issue a HTTP request using ColdFusion's cfhttp tag:

 <cfhttp url=""  

      <cfhttpparam type="url"  
      <cfhttpparam type="url"  
      <cfhttpparam type="url"  
      <cfhttpparam type="url"  
      <cfhttpparam type="url"  

For the purpose of this example, I have specified the latitude and longitude values for 'Sydney, Australia' (I've lived here!!) and have specified the type of business as doctor and book_store. The radius is specified as 2000 meters (2 Kms) and the sensor is set to false. The output format is specified as json.

The json response would contain three root elements: status, results and html_attributions. If there were no errors in performing the request operation and the response contained at least one result then the response status is set to "OK". The result element is an array of places sent in response to a request, this would include the place name, its geometry (latitude and longitude information), place id, reference, icon, types, vicinity.

The results array in the response can then be used to add places to the ColdFusion's map. However, on a Google Map when a user clicks on a location a popup is shown which includes the Address and the Phone number of the selected location. To get more details on a particular location, another request should be made to retrieve the place details such as address, phone number, rating.

Place Detail requests - retrieve place details:

Similar to the previous one, the HTTP request to retrieve the place details is:

As mentioned earlier, output can be either json or xml. The reference value obtained from the previous HTTP call (Place Search request) is then passed as a parameter to retrieve the place details. Other required parameters include the sensor and the key. The cfhttp request to get the details is of the form:

 <cfloop array="#arrayResults#"  
      <cfhttp url=""  
           <cfhttpparam type="url"  
           <cfhttpparam type="url"  
           <cfhttpparam type="url"  
      <cfset placeDetails = #deserializeJSON(placeDetails.fileContent).result#>  
      <cfset arrayAppend(windowContent,   
                "<h3>" & & "</h3><br><h5>" & placeDetails.formatted_address &   
 "<br>Phone: " & placeDetails.formatted_phone_number & "</h5>")/>  

As seen in the above code, the arrayResults containing the results of the place search request is iterated in the cfloop tag. The reference value in the arrayResults is then used in each iteration to get the place details. The place details are then used populate the windowContent array, which contains the html markup to show when the user clicks on any of the map item.

The CFMAP and CFMAPITEM tag can then be used to render a Google map and add places of interests to the map:

 <cfmap name="myMap"  
      <cfloop array="#arrayResults#"  
           <cfmapitem name=""  

The CFMAPITEM tag is used to add places of interests on the map using the latitude and longitude information obtained from the place search request. The markerwindowcontent attribute would contain the address and the phone number information obtained from place detail request. The map rendered would look similar to the one shown below:


  1. I'm struggling with getting this to work.  I have tried to use the exact code above (except substituting API_Key for my Google Maps API key) and I get an error - "Variable ARRAYRESULTS is undefined."  Granted, I'm a novice at ColdFusion (and brand new to CFMAP), so I apologize in advance if this is a stupid rookie mistake...

  2. John, the response that you receive from the HTTP request has to be de-serialized. Try putting  before the cfloop tag. I think that would fix it. Let me know if it doesn't I'll send you the cfm file.

  3. Thanks so much, but now I get an error with this CFSET that says "Complex object types cannot be converted to simple values."

  4. Let me know your email id, I'll send the cfm file to you. You can send me your email id through the 'Contact Me' page as well.

  5. Can I please have the working Coldfusion file too.

  6. @disqus_edBetj5y4t, can you send a message through 'Contact Me' form. I don't have your email id.

  7. Very useful article. Thanks for information!
    Guys, specially for you I give a link . It is one of the best online helping recource. They can writy your essay, dissertation and edit your papers!


Post a Comment

Popular posts from this blog

A cheat sheet of keyboard shortcuts in ColdFusion Builder

In my last post I have explained about keyboard shortcuts in ColdFusion Builder 2.0. This blog post contains a list of all shortcut keys and I have listed these keyboard shortcuts based on the categories that it falls into. Well, this post was not planned since users can easily get to know the keyboard shortcuts by navigating to the preferences (ColdFusion -> Profiles -> Keys). However, I met Joshua at Scotch on the rocks in Edinburgh and he suggested that it would be nice to have the list of keyboard shortcuts handy. So this post is for those who would like to have the list with them and refer it whenever required.

Keyboard shortcuts for inserting text:

These are the keyboard shortcuts which are used to insert some text into the editor:

CommandKeyboard shortcuts on WindowsKeyboard shortcuts on MacInsert anchor tagCTRL + T, LCMD + T, LInsert bold tagCTRL + T, BCMD + T, BInsert br tagCTRL + T, RCMD + T, RInsert cfabortCTRL + T, ACMD + T, AInsert cfdumpCTRL + T, DCMD + T, DInsert cfs…

Custom validation messages for HTML5 Input elements using the constraint validation API

HTML5 has introduced several input types such as EMAIL, URL, RANGE, SEARCH, DATE, TIME, etc,. Most of the modern browsers have implemented them and are ready to be used in a HTML document. Another exciting feature introduced in HTML5 is the form validation. Instead of writing JavaScript to validate users input, browsers can now validate it and show an appropriate message if the validation fails. The validation message is shown in line with the field for which the validation has failed. The default error message is shown when the validation fails. In this post I'll explain how these error messages can be changed.

De-obfuscating javascript code in Chrome Developer Tools

I had blogged about JavaScript debugging with Chrome Developer Tools some time back, wherein I have explained how these developer tools can help in debugging javascript code. Today Google Chrome 12 was released and my Chrome browser was updated to this version. As with every release, there have been some improvements made on performance, usability etc,. One feature that stood out for me is the ability to De-obfuscate the javascript code.

What is Minification?

Minification is the process of removing unnecessary characters such as white spaces, comments, new lines from the source code. These otherwise would be added to make the code more readable. Minifying the source code helps in reducing the file size and thereby reducing the time taken to download the file. This is the reason why most of the popular javascript libraries such as jQuery are minified. A minified jQuery file is of 31 KB in size where as an uncompressed one is about 229 KB. Unfortunately, debugging minified javascript file…