Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic google map InfoWindow loading content of last record in loop
    primarykey
    data
    text
    <p>I'm having an issue where the content in my popup (when marker clicked) is showing the content of my last record.</p> <p>I found a bit of help <a href="https://stackoverflow.com/questions/3576488/google-maps-infowindow-only-loading-last-record-on-markers">here</a>, but I'm still having issues.</p> <p>here's my code</p> <p>collection.js</p> <pre><code>[ { "lat": "-25.363882", "lng": "131.044922", "category": "cat1", "title": "Heading #1", "description": "desc1", "imageurl": "http://ursispaltenstein.ch/blog/images/uploads_img/national_geographic_wallpaper_1.jpg", "pageLink": "http://www.google.com" }, { "lat": "-26.363882", "lng": "200.044922", "category": "cat2", "title": "Heading #2", "description": "desc2", "imageurl": "http://www.creativepics.org/wp-content/uploads/2009/10/National-Geographic-Wallpapers-002.jpg", "pageLink": "http://www.google.com" } , { "lat": "-28.363882", "lng": "81.044922", "category": "cat3", "title": "Heading #3", "description": "desc3", "imageurl": "http://blog.rapidsea.com/wp-content/uploads/2008/03/20080316-bora-bora-national-geographic.jpg", "pageLink": "http://www.google.com" } ] </code></pre> <p>page javascript</p> <pre><code>var pointMap = { map: null } $(function () { pointMap.init('#map_canvas', new google.maps.LatLng(0, 0), 2); pointMap.placeMarkers('collection.js'); }); pointMap.init = function (selector, latLng, zoom) { var myOptions = { zoom: zoom, center: latLng, mapTypeId: google.maps.MapTypeId.HYBRID } this.map = new google.maps.Map($(selector)[0], myOptions); } pointMap.placeMarkers = function (filename) { $.getJSON(filename, function (data) { for (var x = 0; x &lt; data.length; x++) { var location = data[x]; var point = new google.maps.LatLng(parseFloat(location.lat), parseFloat(location.lng)); var marker = new google.maps.Marker({ position: point, map: pointMap.map, title: location.title }); var popupContent = '&lt;div id="locationContent"&gt;' + '&lt;div&gt;' + location.category + '&lt;/div&gt;' + '&lt;div&gt;' + location.title + '&lt;/div&gt;' + '&lt;div&gt;' + location.description + '&lt;/div&gt;' + '&lt;div&gt;&lt;a href="' + location.pageLink + '"&gt;See This Story &gt;&gt;&lt;/a&gt;&lt;/div&gt;' + '&lt;div&gt;&lt;img width="250" src="' + location.imageurl + '" /&gt;&lt;/div&gt;' + '&lt;/div&gt;'; var infoWindow = new google.maps.InfoWindow(); google.maps.event.addListener(marker, 'click', function () { infoWindow.setContent(popupContent); infoWindow.open(pointMap.map, this); }); } }); } </code></pre> <p>html</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; // javascript from above &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="map_canvas"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The markers all load in the correct places and windows all open in the correct places, but the content loaded in the InfoWindow (popupContent) is of my last record for all the markers.</p> <p>thanks for any help</p>
    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