I am a beginner to write a webpage and would like to show some markers in the google map with infowindows. However, i found that the infowindow always show the information of the last records. With reference from the previous article in stackoverflow, i found that the problem is mostly likely caused by the common closure problem in javascript but i find it difficult to understand how to fix the problem in my coding. Can any one help?
Besides, i would like to ask one simple html question. How to create a href if the PDF name is a variable as shown in the coding. Many thanks!!!
var ShowAll=function() {
var URL2="Show_all_trig.php";
$.ajax({
url: URL2,
type: "POST",
dataType: "json",
success: function(data){
$.each(data, function(i, item) {
station_num = item.station_num;
trig_name = item.trig_name;
loc_x = item.loc_x;
loc_y = item.loc_y;
loc = new google.maps.LatLng(loc_x, loc_y);
var trigicon = 'images/Start2.png';
marker = new google.maps.Marker({
map: map,
position: loc,
icon: trigicon,
title: trig_name
})
markersArray.push(marker)
html = "<b>Trig. Station Name: </b>" + trig_name + "<br/> <b>Station Number: </b>" + station_num + "<br/> <b>Sketch: </b>" +"<a target='_blank' href= 'summarysheet/'+ 'station_num +'.pdf'>station_num</a>";
google.maps.event.addListener(marker, 'click', function() {
//alert (html);
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
});
},
error:function(xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
}