Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps API V3 infowindow error: "infowindow not defined"
    primarykey
    data
    text
    <p>I have a list of Google Maps API markers in a dictionary called <code>markerList</code>. All of them are being placed on the map. Then I create an array of all my <code>infowindow</code>'s. Then I need to <code>addListener</code> for each of them so that when the marker is clicked on the map, it will call <code>infowindow.open</code> on the correct map and infowindow. </p> <p>Unfortunately, when I click on a marker, I get the following error in firebug console:</p> <pre><code>infowindow is not defined infowindow.open(map,infowindowList[window]); </code></pre> <p>Here is my code:</p> <pre><code> var infowindowList = {}; for (var aMarker in markerList){ infowindowList[aMarker] = new google.maps.InfoWindow({ content: "This is a test!", size: new google.maps.Size(50,50) }); console.log(infowindowList[aMarker]); } console.log("Done creating infowindowList...\n...Adding listeners"); for (var window in infowindowList){ google.maps.event.addListener(markerList[window], 'click', function() { // infowindow.open(map,infowindowList[window]); // wrong, see Edit infowindowList[window].open(map,markerList[window]); }); console.log("added listener for window: ", infowindowList[window]); } </code></pre> <p><strike><strong>I think</strong> this is happening because in the <code>google.maps.event.addListener(markerList[window]...</code> function, I register the function to be run on click as <code>infowindow.open(map,infowindowList[window])</code>, but that value, <code>window</code>, is local to the function, and so when I click on the marker, that function doesn't work, because it doesn't know what <code>window</code> is. Is that correct?</strike></p> <p>EDIT: As geocodezip pointed out, <code>infowindow</code> does not exist. So I changed it to <code>infowindowList[window].open(map,markerList[window]);</code>, also changing the last argument to <code>markerlist[window]</code> because it should be a marker as an arg, not another infowindow. </p>
    singulars
    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