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 6631671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:34:46+00:00 2026-05-25T22:34:46+00:00

I’m using the code below to link an HTML list to markers on a

  • 0

I’m using the code below to link an HTML list to markers on a map. When I click on the markers, the InfoWindow opens without any problem. However when I click on the list item, although the map pans correctly and centres on the appropriate marker, I cannot get the InfoWindow to open at the same time.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Map My Finds - All Locations</title>
        <link rel="stylesheet" href="css/mylocations.css" type="text/css" media="all" />
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script>
    <style>
    div#locationslist div{     
    cursor:pointer; } 
    </style>    

        <div id="map"></div> 
        <div id="locationslist"></div> 

        <body onload="showLocations()"> 

            <script type="text/javascript"> 

                var map; 
                var gmarkers = new Array();
                var locationslist;

                function showLocations() { 
                map = new google.maps.Map(document.getElementById("map"), { 
                center: new google.maps.LatLng(54.312195845815246,-4.45948481875007), 
                zoom:6, 
                mapTypeId: 'terrain' 
                }); 
                var infoWindow = new google.maps.InfoWindow; 

                // Change this depending on the name of your PHP file 
                downloadUrl("loadmylocations.php", function(data) { 
                var xml = data.responseXML; 
                gmarkers = xml.documentElement.getElementsByTagName("marker"); 
                var bounds = new google.maps.LatLngBounds(); 
                for (var i = 0; i < gmarkers.length; i++) { 
                var locationname = gmarkers[i].getAttribute("locationname"); 
                var address = gmarkers[i].getAttribute("address"); 
                var locationid = gmarkers[i].getAttribute("locationid"); 
                var point = new google.maps.LatLng( 
                parseFloat(gmarkers[i].getAttribute("osgb36lat")), 
                parseFloat(gmarkers[i].getAttribute("osgb36lon"))); 
                var html = "<b>" + locationname + "</b> <br/>" + address; 
                bounds.extend(point);  
                var marker = new google.maps.Marker({ 
                map: map, 
                position: point, 
                locationid: locationid 
                }); 
                bindInfoWindow(marker, map, infoWindow, html);  
                locationslist += "<div onclick=scrollToMarker(" + i + ")>"+locationname+"</div>"; 
                }        
                map.setCenter(bounds.getCenter()); 
                map.fitBounds(bounds);  
                //display company data in html 
                document.getElementById("locationslist").innerHTML = locationslist; 
                });  
                } 

                function scrollToMarker(index) {  
                var point = new google.maps.LatLng( 
                parseFloat(gmarkers[index].getAttribute("osgb36lat")),  
                parseFloat(gmarkers[index].getAttribute("osgb36lon")) 
                ); 
                map.panTo(point);  
                } 

                function bindInfoWindow(marker, map, infoWindow, html) { 
                google.maps.event.addListener(marker, 'click', function() { 
                infoWindow.setContent(html); 
                infoWindow.open(map, marker); 
                }); 
                } 

                function downloadUrl(url, callback) { 
                var request = window.ActiveXObject ? 
                new ActiveXObject('Microsoft.XMLHTTP') : 
                new XMLHttpRequest; 

                request.onreadystatechange = function() { 
                if (request.readyState == 4) { 
                request.onreadystatechange = doNothing; 
                callback(request, request.status); 
                } 
                }; 

                request.open('GET', url, true); 
                request.send(null); 
                } 
                function doNothing(){ 
                } 

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

UPDATED CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Map My Finds - All Locations</title> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script> 
<style> 
    div#locationslist div{cursor:pointer; }  
    html { height: 100% } 
    body { height: 100%; margin: 0; padding: 0 } 
    #map { height: 70%; width:70% } 
</style>     

<script type="text/javascript">  
var map;  
var gmarkers = []; 
var locationslist = ""; 
var arrMarkers = [];    // add our markers to this array 

function showLocations() {  
    map = new google.maps.Map(document.getElementById("map"), {  
        center: new google.maps.LatLng(54.312195845815246,-4.45948481875007),  
        zoom:6,  
        mapTypeId: google.maps.MapTypeId.TERRAIN 
    });  
    var infoWindow = new google.maps.InfoWindow;  
      downloadUrl("loadmylocations.php", function(data) { 
                var xml = data.responseXML; 
                gmarkers = xml.documentElement.getElementsByTagName("marker"); 
    var bounds = new google.maps.LatLngBounds();  
    for (var i = 0; i < gmarkers.length; i++) {  
        var locationname = gmarkers[i]["locationname"];  
        var address = gmarkers[i]["address"];  
        //var locationid = gmarkers[i]["locationid"];  
        var point = new google.maps.LatLng(  
            parseFloat(gmarkers[i]["osgb36lat"]),  
            parseFloat(gmarkers[i]["osgb36lon"]));  
        var html = "<b>" + locationname + "</b> <br/>" + address;  
        bounds.extend(point);   
        var marker = new google.maps.Marker({  
            map: map,  
            position: point 
        });  

        arrMarkers.push(marker); 

        bindInfoWindow(marker, map, infoWindow, html);   
        locationslist += "<div onclick=scrollToMarker(" + i + ")>"+locationname+"</div>";  
    } 
    map.setCenter(bounds.getCenter());  
    map.fitBounds(bounds);   
    //display company data in html  
    document.getElementById("locationslist").innerHTML = locationslist;  
 });  
                }  

function scrollToMarker(index) {   
    var point = new google.maps.LatLng(  
        parseFloat(gmarkers[index]["osgb36lat"]),   
        parseFloat(gmarkers[index]["osgb36lon"])  
    );  

    map.panTo(point);  

    google.maps.event.trigger(arrMarkers[index], 'click');  
}  

function bindInfoWindow(marker, map, infoWindow, html) {  
    google.maps.event.addListener(marker, 'click', function() {  
        infoWindow.setContent(html);  
        infoWindow.open(map, marker);  
    });  
}  
</script>  
</head> 
<body onload="showLocations()">  
    <div id="map"></div>  
    <div id="locationslist"></div>   
</body>  
</html> 
  • 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-25T22:34:47+00:00Added an answer on May 25, 2026 at 10:34 pm

    You’ve binded the click event on the marker to open an infowindow. What you want to do is trigger that click, i.e. as if the user had done it themselves.

    Something like this:

    google.maps.event.trigger(marker, 'click');
    

    The hard part will be for you to identify which marker the click event is firing on. Suggest you have an array of all your markers. At the same time as you call scrollToMarker, also do this trigger, and pass through the index parameter too, to identify which marker in your array you’re wanting to ‘click’

    Update: ok, here’s a working example of what I mean. I’ve removed your Ajax request part and put in some dummy marker data, but it should be simple enough for you to figure out how to integrate into your code.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Map My Finds - All Locations</title>
    <link rel="stylesheet" href="css/mylocations.css" type="text/css" media="all" />
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script>
    <style>
        div#locationslist div{cursor:pointer; } 
        html { height: 100% }
        body { height: 100%; margin: 0; padding: 0 }
        #map { height: 70%; width:70% }
    </style>    
    
    <script type="text/javascript"> 
    var map; 
    var gmarkers = [];
    var locationslist = "";
    var arrMarkers = [];    // add our markers to this array
    
    function showLocations() { 
        map = new google.maps.Map(document.getElementById("map"), { 
            center: new google.maps.LatLng(54.312195845815246,-4.45948481875007), 
            zoom:6, 
            mapTypeId: google.maps.MapTypeId.TERRAIN
        }); 
        var infoWindow = new google.maps.InfoWindow; 
    
        gmarkers = [
            {locationname: "One", address: "blah", osgb36lat: "51.482238", osgb36lon: "0.001581"},
            {locationname: "Two", address: "blahblah", osgb36lat: "51.473364", osgb36lon: "0.011966"},
            {locationname: "Three", address: "blahblahblah", osgb36lat: "51.471974", osgb36lon: "-0.000651"},
            {locationname: "Four", address: "blahblahblahblah", osgb36lat: "51.472108", osgb36lon: "-0.002196"},
            {locationname: "Five", address: "foobar", osgb36lat: "51.474995", osgb36lon: "-0.003827"},
        ];
    
        var bounds = new google.maps.LatLngBounds(); 
        for (var i = 0; i < gmarkers.length; i++) { 
            var locationname = gmarkers[i]["locationname"]; 
            var address = gmarkers[i]["address"]; 
            //var locationid = gmarkers[i]["locationid"]; 
            var point = new google.maps.LatLng( 
                parseFloat(gmarkers[i]["osgb36lat"]), 
                parseFloat(gmarkers[i]["osgb36lon"])
            ); 
            var html = "<b>" + locationname + "</b> <br/>" + address; 
            bounds.extend(point);  
            var marker = new google.maps.Marker({ 
                map: map, 
                position: point
            }); 
    
            arrMarkers.push(marker);
    
            bindInfoWindow(marker, map, infoWindow, html);  
            locationslist += "<div onclick=scrollToMarker(" + i + ")>"+locationname+"</div>"; 
        }
        map.setCenter(bounds.getCenter()); 
        map.fitBounds(bounds);  
        //display company data in html 
        document.getElementById("locationslist").innerHTML = locationslist; 
    } 
    
    function scrollToMarker(index) {  
        var point = new google.maps.LatLng( 
            parseFloat(gmarkers[index]["osgb36lat"]),  
            parseFloat(gmarkers[index]["osgb36lon"]) 
        ); 
    
        map.panTo(point); 
    
        google.maps.event.trigger(arrMarkers[index], 'click'); 
    } 
    
    function bindInfoWindow(marker, map, infoWindow, html) { 
        google.maps.event.addListener(marker, 'click', function() { 
            infoWindow.setContent(html); 
            infoWindow.open(map, marker); 
        }); 
    } 
    </script> 
    </head>
    <body onload="showLocations()"> 
        <div id="map"></div> 
        <div id="locationslist"></div>  
    </body> 
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have thousands of HTML files to process using Groovy/Java and I need to
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.