Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps Sidebar
    primarykey
    data
    text
    <p>I have been using <a href="https://stackoverflow.com/questions/4904549/open-infowindow-of-specific-marker-from-outside-google-maps-v3">Open infoWindow of specific marker from outside Google Maps (V3)</a> to try and implement a sidebar into one of my map pages. I've put together the following code (see below) but I'm getting an error when I try and open the page. The error is 'document.getElementById(...)' is null or not an object' and it is pointing to this line : </p> <pre><code>document.getElementById("locationslist").innerHTML = locationslist; </code></pre> <p>I've been looking at this now for quite some time and I just can't see what the error is. </p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;All Locations&lt;/title&gt; &lt;link rel="stylesheet" href="css/alllocationsstyle.css" type="text/css" media="all" /&gt; &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&amp;language=en"&gt;&lt;/script&gt; &lt;div id="map"&gt;&lt;/div&gt; &lt;div id="locationslist"&gt;&lt;/div&gt; &lt;body onload="showLocations()"&gt; &lt;script type="text/javascript"&gt; 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("phpfile.php", function(data) { var xml = data.responseXML; gmarkers = xml.documentElement.getElementsByTagName("marker"); var bounds = new google.maps.LatLngBounds(); for (var i = 0; i &lt; 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 = "&lt;b&gt;" + locationname + "&lt;/b&gt; &lt;br/&gt;" + address; bounds.extend(point); var marker = new google.maps.Marker({ map: map, position: point, locationid: locationid }); bindInfoWindow(marker, map, infoWindow, html); locationslist += "&lt;div onclick=scrollToMarker(" + i + ")&gt;"+locationname+"&lt;/div&gt;"; } map.setCenter(bounds.getCenter()); map.fitBounds(bounds); //display company data in html document.getElementById("locationslist").innerHTML = locationslist; }); } function scrollToMarker(index) { map.panTo(gmarkers[index].getPosition()); } 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(){ } &lt;/script&gt; &lt;/head&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload