Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 821313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:37:13+00:00 2026-05-15T02:37:13+00:00

I need to display multiple markers on a map, each with their own infowindow.

  • 0

I need to display multiple markers on a map, each with their own
infowindow. I have created the individual markers without a problem,
but don’t know how to create the infowindows for each.

I am generating a map using the V3 API within an ASP-based website,
with markers being created from a set of DB records. The markers are
created by looping through a rs and defining a marker() with the
relevant variables:

            var myLatlng = new google.maps.LatLng(lat,long);
            var marker = new google.maps.Marker({
                    map: map,
                    position: myLatlng,
                    title: 'locationname',
                    icon: 'http://google-maps-icons.googlecode.com/files/park.png'
            });

This is creating all the relevant markers in their correct locations.

What I need to do now, and am not sure of how to achieve is give each
of them their own unique infowindow which I can use to display
information and links relevant to that marker.

Source

                <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
                <script language="javascript">
                $(document).ready(function() {

                     //Google Maps 
                        var myOptions = {
                          zoom: 5,
                          center: new google.maps.LatLng(-26.66, 122.25),
                       mapTypeControl: false,
                          mapTypeId: google.maps.MapTypeId.ROADMAP,
                       navigationControl: true,
                       navigationControlOptions: {
                         style: google.maps.NavigationControlStyle.SMALL
                       }

                        }

                        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

                      <!-- While locations_haslatlong not BOF.EOF -->
                            <% While ((Repeat1__numRows <> 0) AND (NOT locations_haslatlong.EOF)) %>
                      var myLatlng = new google.maps.LatLng(<%=(locations_haslatlong.Fields.Item("llat").Value)%>,<%=(locations_haslatlong.Fields.Item("llong").Value)%>);
                      var marker = new google.maps.Marker({
                       map: map,
                       position: myLatlng,
                       title: '<%=(locations_haslatlong.Fields.Item("ldescription").Value)%>',
                       icon: 'http://google-maps-icons.googlecode.com/files/park.png',
                       clickable: true,
                      }); 
                      <% 
                      Repeat1__index=Repeat1__index+1
                      Repeat1__numRows=Repeat1__numRows-1
                      locations_haslatlong.MoveNext()
                      Wend
                      %>           
                            <!-- End While locations_haslatlong not BOF.EOF -->

                      google.maps.event.addListener(marker, 'click', function() {
                      infowindow.open(map,marker);
                      });

                      google.maps.event.addListener(marker, 'dblclick', function() {
                      map.setZoom(14);
                      });


                                    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:37:13+00:00Added an answer on May 15, 2026 at 2:37 am

    The problem is in your call to addListener()

    While you loop through your recordset and write out the javascript again and again and again and again for adding a marker to the map, you only call the event listener once. Also, you never actually create any objects of the InfoWindow type, so you never have anything to call open() on.

    The quick and dirty solution is to add this after you create your marker but before you end your While loop.

    var infowindow = new google.maps.InfoWindow({ 
        content: '<%=(locations_haslatlong.Fields.Item("field_or_fields_containing_data_for_info_window").Value)%>' 
    });
    google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
    });
    

    But don’t do this — you’re using VB to write totally redundant Javascript for you, when you could be using VB to fetch what you need, and then let Javascript do the work that you need done with the data.

    The better way to do what you are trying to do is to rewrite your VB to create an array of Javascript objects, each one containing a park’s information. Then use Javascript to loop over that array and set up the markers and their associated infoWindows for you.

    Outlining the proposed solution:

    // Create an array to hold a series of generic objects
    // Each one will represent an individual marker, and contain all the 
    // information we need for that marker.  This way, we can reuse the data
    // on the client-side in other scripts as well.
    var locations_array = [<%
    While (
        (Repeat1__numRows <> 0) 
        AND (NOT locations_haslatlong.EOF)
    ) 
    %>
    { 
    latitude: <%=(locations_haslatlong.Fields.Item("llat").Value)%>,
    longitude: <%=(locations_haslatlong.Fields.Item("llong").Value)%>,
    title: "<%=(locations_haslatlong.Fields.Item("ldescription").Value)%>",
    infoWindowContent: "<%=(locations_haslatlong.Fields.Item("field_or_fields_containing_data_for_info_window").Value)%>"
    },
    <% 
      Repeat1__index=Repeat1__index+1
      Repeat1__numRows=Repeat1__numRows-1
      locations_haslatlong.MoveNext()
      Wend
    %>];
    
    var x = locations_array.length;
    while (--x) {
        // Grab an individual park object out of our array
        var _park = locations_array[x]
        var myLatlng = new google.maps.LatLng(_park.latitude,_park.longitude);
        var marker = new google.maps.Marker({
            map: map,
            position: myLatlng,
            title: _park.title,
            icon: 'http://google-maps-icons.googlecode.com/files/park.png',
            clickable: true,
        }); 
        var infowindow = new google.maps.InfoWindow({ 
            content: _park.infoWindowContent
        });
        google.maps.event.addListener(marker, 'click', function() {
            infowindow.open(map,marker);
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to display multiple pieces of data in a combobox, but I can't
I need to have multiple time frame on a zedgraph. I have to display
I have an application where I need to display a list of numbers, but
I need to display additional information, like a tooltip, but it's a lot of
I have a master-detail page, in which I use GridView to display multiple rows
Hi I am new to iPhone. What I need is, have to display only
i have a input tag which is non editable, but some times i need
I have a requirement to display multiple linear progress bars on my UI. These
I need to display multiple lines of text in an Alert Dialog. If I
I need some help finding a jQuery solution to display multiple images in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.