NetTalk Central

Author Topic: Question about displaying a Google map with multiple markers  (Read 3440 times)

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Question about displaying a Google map with multiple markers
« on: November 23, 2012, 08:14:39 PM »
The following code will display a Google map with one marker:

   <html>
     <body>
      <p>Blah</p>
      <div id="map_canvas" style="width:425px; height:550px"></div>
      <p>Blah</p>

      <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
      <script type="text/javascript">

        var map;
        var markers = [];

        initialize();

        function initialize() {
          var myOptions = {
            zoom: 10,
            center: new google.maps.LatLng(33.7309444, -085.8347333),
            mapTypeId: google.maps.MapTypeId.ROADMAP
          }
          map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

          addMarker(new google.maps.LatLng(33.7309444, -085.8347333), "Alien");

        }

        function addMarker(latlng, myTitle) {
          markers.push(new google.maps.Marker({
            position: latlng,
            map: map,
            title: myTitle,
            icon: "http://maps.google.com/mapfiles/marker" + String.fromCharCode(markers.length + 65) + ".png"
          }));   
        }

      </script>
    </body>
  </html>

Thus bit here:
addMarker(new google.maps.LatLng(33.7309444, -085.8347333), "Alien");
places the marker on the map.  This line can be repeated with different coordinates to place multiple markers. 

I would like to loop through a table a get stored coordinates and duplicate the line above as many times as required to display as many markers as I need. 

So, that's my question, how would I loop through a table (I can do that part) and add the lines to the above javascript code?

Thank you!!!

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Question about displaying a Google map with multiple markers
« Reply #1 on: November 23, 2012, 10:06:42 PM »
Hi Don,

You're a little vague on the context here. Are you embedding in a static page? In a NetWebPage?

Perhaps an example would be appropriate.

cheers
Bruce

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: Question about displaying a Google map with multiple markers
« Reply #2 on: November 24, 2012, 03:20:03 AM »
NetWebPage.

I attached a screenshot of an example.

I think I have figured out the answer to my question....but please suggest how you would do this.

Thanks,

Don


[attachment deleted by admin]
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Question about displaying a Google map with multiple markers
« Reply #3 on: November 25, 2012, 10:20:09 PM »
I would do it by adding embed code to the page.

cheers
Bruce

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: Question about displaying a Google map with multiple markers
« Reply #4 on: November 26, 2012, 03:28:52 AM »
I got it going.

It's easy to make things harder than it has to be...

Thanks,

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11