Google Maps

Is there some reason why I cannot have 2 (or 3) Google Maps on the same web page?

I am using the JavaScript methods to populate the maps.

Works fine with one, NOT with two.

I can show the code, but it's pretty messy; it's generated by php on the server.
Richard KortsAsked:
Who is Participating?
 
Molnar IstvánHelpDesk / ProgrammerCommented:
 i used the first one in my websites
you can add multiple google maps like this:
    <script type="text/javascript">
    //<![CDATA[
    function load() {
      if (GBrowserIsCompatible()) {
        var map1 = new GMap2(document.getElementById("map"));
        map1.setCenter(new GLatLng(37.4419, -122.1419), 17);

       var map2 = new GMap2(document.getElementById("map1"));
       var point = new GLatLng(-33.9419, 150.9473);
       map2.setCenter(point, 10);
        var marker = new GMarker(point);
        map2.addOverlay(marker);
        GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml('here I am');});
        map2.addControl(new GSmallMapControl());
        map2.removeMapType(G_HYBRID_MAP);
        var mapControl = new GMapTypeControl();
        map2.addControl(mapControl);
      }
    }
window.onload=load;
window.onunload=GUnload;
//]]>
</script>
or you can create separate functions snd load them:
    <script type="text/javascript">
    //<![CDATA[
    function load() {
      if (GBrowserIsCompatible()) 
      {
        var map1 = new GMap2(document.getElementById("map"));
        map1.setCenter(new GLatLng(37.4419, -122.1419), 17);
      }
    }
     function load2() {
      if (GBrowserIsCompatible()) 
      {
       var map2 = new GMap2(document.getElementById("map1"));
       var point = new GLatLng(-33.9419, 150.9473);
       map2.setCenter(point, 10);
        var marker = new GMarker(point);
        map2.addOverlay(marker);
        GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml('here I am');});
        map2.addControl(new GSmallMapControl());
        map2.removeMapType(G_HYBRID_MAP);
        var mapControl = new GMapTypeControl();
        map2.addControl(mapControl);
      }
    }
window.onload=load;
window.onload=load2;
window.onunload=GUnload;
//]]>
</script>

Open in new window

0
 
Richard KortsAuthor Commented:
To quicksilver17:

Thanks. I discovered that is NOT the problem. It is creating the 2nd map, it is only loading it with the LAST point out of about 30 addresses.

Go to http://www.rkassoc.net/LSSGeocoding/LSS_schedule2.php. Click the name "Abelman Bob" in the pulldown list. Note how the 2nd map (to the lower right) only contains ONE point. There should be about 30, plus the green one. You can view source. Sorry it's so messy, I didn't know how to do it except to duplicate most of the JavaScript functions for the 2nd map.

Thanks,

rkorts
0
 
Richard KortsAuthor Commented:
To quicksilver17:

I solved the problem; it was a php logic error.

You get the points.

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.