Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Google Maps (v2) not displaying 1

Status
Not open for further replies.

jman78

Programmer
Jan 15, 2008
44
US
Here's the code I'm using - I don't see what's wrong - If I take out the event listener, I can get markers to show up on the screen, but the map doesn't show.

Anyone see something I missed?

Thanks!

Jason

Code:
<head>
    ...         
              <script type="text/javascript" src="[URL unfurl="true"]http://www.google.com/jsapi?key=[/URL][..My Google API Key...]"></script>  
            <script type="text/javascript">
              google.load("maps", "2");
            </script>
            <script type="text/javascript">
              function initialize() {
                var map = new google.maps.Map2(document.getElementById("map_canvas"));
                    map.setCenter(new google.maps.LatLng(40, -98, 3);
                    map.addControl(new google.maps.LargeMapControl());
              }
            </script>            
 </head>

  <body onload="initialize()" onunload="GUnload()">
   ...

  <div id="map_canvas" style="width: 650px; height: 500px; margin: 5px auto;"></div>

<script type="text/javascript">  
    // Create a map object  
    var map = new google.maps.Map2(document.getElementById("map_canvas"));  
    var bounds = new google.maps.LatLngBounds();

    map.addControl(new google.maps.LargeMapControl());  
    map.setMapType(G_NORMAL_MAP);

        markerHTML = "1792 Filigree Inn Bed & Breakfast "
        geopoint = new google.maps.LatLng(42.7569, -77.4043);
        marker = new google.maps.Marker(geopoint);
        google.maps.Event.addListener(marker, "click",
            function() {
              marker.openInfoWindowHTML(markerHTML);
            }
        map.addOverlay(marker);
   
        markerHTML = "Abner Adams House B & B "
        geopoint = new google.maps.LatLng(42.8992, -77.4313);
        marker = new google.maps.Marker(geopoint);
        google.maps.Event.addListener(marker, "click",
            function() {
              marker.openInfoWindowHTML(markerHTML);
            }
        map.addOverlay(marker);
...
 
Presumably because you're missing a closing bracket after the listener code and thus throwing a syntax error?

Did you check the JS error console in Firefox? I'm sure it would have shown you this...

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hmm.. I'm guessing you didn't check the Fx error console, as it also points out another missing bracket you have:

Code:
map.setCenter(new GLatLng(40, -98, 3)[!])[/!];

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Dan - Thanks for catching that. No, I usually do my init testing in safari, I need to start using the js console. I keep forgetting about it. (don't code much in JS, personally) I was missing the closing parens in the listener code, but no clue why there is a closing parens missing in the setCenter line. It is there in my code, but doesn't seem to show up in 'view source'.

Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top