<p>I am trying to use the Google Maps API in a ColdFusion template that is a border type cflayoutarea container. However, the map simply doesn't show up:</p>

<pre><code>&lt;cfif isdefined("url.lat")&gt;
    &lt;cfset lat="#url.lat#"&gt;
    &lt;cfset lng="#url.lng#"&gt;
&lt;/cfif&gt;    
&lt;head&gt;
&lt;script src=                        "http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=xxxx" type="text/javascript"&gt;
        function getMap(lat,lng){       
            if (GBrowserIsCompatible()) {        
                var map = new GMap2(document.getElementById("map_canvas"));
                var pt= new GLatLng(lat,lng);
                map.setCenter(pt, 18,G_HYBRID_MAP);      
                map.addOverlay(new GMarker(pt));
            }    
        }    
&lt;/script&gt;
&lt;/head&gt;  
&lt;cfoutput&gt;
&lt;body onLoad="getMap(#lat#,#lng#)" onUnload="GUnload()"&gt;
    Map:&lt;br&gt;
    &lt;div id="map_canvas" style="width: 500px; height: 300px"/&gt;
&lt;/body&gt;
&lt;/cfoutput&gt;"
</code></pre>

<p>where lat and lng are the co-ordinates in degree.decimal format. I have traced down to the line where GBrowserIsCompatible() somehow never returns TRUE and thus no further action was taken.</p>

<p>If opened separately the template works perfectly but just not when opened as a cflayoutarea container. Anyone has experience in this? Any suggestions is much appreciated.</p>

<p>Lawrence</p>

<p>Using CF 8.01, Dreamweaver 8</p>

<hr>

<p>Tried your suggestion but still doesn't work; the map only shows when the calling code is inline. However, if this container page was called from yet another div the map disappears again.</p>

<p>I suspect this issue is related to the cflayout container; I'll look up the Extjs doc to see if there're any leads to a solution.</p>

[{'answer_id': 80298, 'author': 'convex hull', 'author_id': 10747, 'author_profile': 'https://Stackoverflow.com/users/10747', 'pm_score': 0, 'selected': False, 'text': "<p>Maybe the layout area doesn't have the right <strong>style</strong>.  I think you may have to give the map_canvas a</p>\n\n<pre><code>position: absolute\n</code></pre>\n\n<p>or </p>\n\n<pre><code>position: relative\n</code></pre>\n\n<p>That's just a hunch.</p>\n"}, {'answer_id': 82887, 'author': 'Adam Tuttle', 'author_id': 751, 'author_profile': 'https://Stackoverflow.com/users/751', 'pm_score': 0, 'selected': False, 'text': '<p>CFLayoutArea is a new AJAX tag added with ColdFusion version 8. (In addition to tags like CFWindow, CFDiv, etc.)</p>\n\n<p>Within the AJAX-loaded content of any of these new tags, external JavaScript must be included from the containing page. In your case, that would be the page that includes the &lt;cflayout&gt; tag.</p>\n\n<p>Try something like this:</p>\n\n<p>in index.cfm (or whatever your containing file is):</p>\n\n<pre><code>&lt;script src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=xxxx" type="text/javascript"&gt;\n    function getMap(lat,lng){               \n        if (GBrowserIsCompatible()) {        \n            var map = new GMap2(document.getElementById("map_canvas"));\n            var pt= new GLatLng(lat,lng);\n            map.setCenter(pt, 18,G_HYBRID_MAP);      \n            map.addOverlay(new GMarker(pt));\n        }    \n    }\n&lt;/script&gt;\n&lt;cflayout&gt;...&lt;/cflayout&gt;\n</code></pre>\n\n<p>map.cfm (content of your map CFLayout tab):</p>\n\n<pre><code>&lt;cfif structKeyExists(url, "lat")&gt;\n    &lt;cfset variables.lat = url.lat /&gt;\n    &lt;cfset variables.lng = url.lng /&gt;\n&lt;/cfif&gt;    \n&lt;head&gt;&lt;/head&gt;  \n&lt;cfoutput&gt;\n    &lt;body onLoad="getMap(#variables.lat#,#variables.lng#)" onUnload="GUnload()"&gt;\n        Map:&lt;br&gt;\n        &lt;div id="map_canvas" style="width: 500px; height: 300px"/&gt;\n    &lt;/body&gt;\n&lt;/cfoutput&gt;\n</code></pre>\n'}, {'answer_id': 100406, 'author': 'lawrencem49', 'author_id': 15007, 'author_profile': 'https://Stackoverflow.com/users/15007', 'pm_score': 2, 'selected': True, 'text': '<p>Success! (sort of...)</p>\n\n<p>Finally got it working, but not in the way Adam suggested:</p>\n\n<pre><code>&lt;script src= "http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=xxxx" type="text/javascript"&gt;&lt;/script&gt;\n&lt;script type="text/javascript"&gt;\n    getMap=function(lat,lng){               \n        if (GBrowserIsCompatible()){\n            var map = new GMap2(document.getElementById("map_canvas"));\n            var pt = new GLatLng(lat,lng);\n            map.setCenter(pt, 18,G_HYBRID_MAP);      \n            map.addOverlay(new GMarker(pt));  \n        }    \n    }\n&lt;/script&gt;  \n\n &lt;cflayout name="testlayout" type="border"&gt;\n    &lt;cflayoutarea name="left" position="left" size="250"/&gt;\n     &lt;cflayoutarea name="center" position="center"&gt; \n            &lt;!--- sample hard-coded co-ordinates ---&gt;\n        &lt;body onLoad="getMap(22.280161,114.185096)"&gt;\n        Map:&lt;br /&gt;\n        &lt;div id="map_canvas" style="width:500px; height: 300px"/&gt;\n        &lt;/body&gt;\n      &lt;/cflayoutarea&gt; \n&lt;!---       &lt;cflayoutarea name="center" position="center" source="map_content.cfm?lat=22.280161&amp;lng=114.185096"/&gt; ---&gt;\n&lt;/cflayout&gt; \n</code></pre>\n\n<p>The whole thing must be contained within the same file or it would not work. My suspicion is that the getElementByID function, as it stands, cannot not reference an element that is outside of its own file. If the div is in another file (as in Adam\'s exmaple), it results in an undefined map, ie a map object is created but with nothing in it.</p>\n\n<p>So I think this question is now elevated to a different level: how do you reference an element that is inside an ajax container? </p>\n'}, {'answer_id': 101544, 'author': 'Adam Tuttle', 'author_id': 751, 'author_profile': 'https://Stackoverflow.com/users/751', 'pm_score': 1, 'selected': False, 'text': '<blockquote>\n  <p>So I think this question is now elevated to a different level: how do you reference an element that is inside an ajax container?</p>\n</blockquote>\n\n<p>It should be possible reference an element loaded via AJAX -- just not until the element is on screen (so not on page load). It looks like getMap() triggers everything. (Is that right?)</p>\n\n<p>Try this: Take exactly what you have as your inline-content for the map tab, and make it the content of map_content.cfm; <strong>then</strong> instead of using body onload to fire the event, write it inline, after the div is defined:</p>\n\n<pre><code>&lt;body&gt;\n    Map:&lt;br /&gt;\n    &lt;div id="map_canvas" style="width:500px; height: 300px"/&gt;\n    &lt;script type="text/javascript"&gt;\n        getMap(22.280161,114.185096);\n    &lt;/script&gt;\n&lt;/body&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/80278', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/15007/']