Solved

Google Maps

Posted on 2011-03-07
3
518 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:Richard Korts
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Molnar István earned 500 total points
ID: 35066120
 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
 

Author Comment

by:Richard Korts
ID: 35070830
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
 

Author Comment

by:Richard Korts
ID: 35072649
To quicksilver17:

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

You get the points.

Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I feel like more and more people want to know how to programmatically convert addresses into geospatial locations. So in this article, I will show you how you can do it with Bing Maps. I'm going to use PowerShell, which is a nice scripting language,…
Introduction This article is designed to assist GIS (Geographic Information System) and GPS (Global Positioning System) developers using ESRI ArcGIS and other spatial information management systems.   For the uninitiated the concept of projectio…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question