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 KortsBusiness Owner / Chief DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Molnár 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KortsBusiness Owner / Chief DeveloperAuthor 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
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
To quicksilver17:

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

You get the points.

Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
GIS/GPS Programming

From novice to tech pro — start learning today.