So google maps infowindow always displays the content of the last map item. Based on some research I stumbled accross this. However it still doesn't work for me here is my code.
function bindInfoWindow(marker, map, infowindow, html) {
marker.addListener('click', function () {
infowindow.setContent(html);
infowindow.open(map, this);
});
}
for (var x = 0; x < filtered_pins.length; x++) {
var links = filtered_pins[x].description + '<a href="' + filtered_pins[x].slug + '">read more..</a>';
links_arr.push(links);
$.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address=' + filtered_pins[x].city + '&sensor=false', null, function (data) {
//console.log('4th'+ links);
var p = data.results[0].geometry.location
var latlng = new google.maps.LatLng(p.lat, p.lng);
var marker = new google.maps.Marker({
position: latlng,
map: map,
});
var infowindow = new google.maps.InfoWindow();
//marker.addListener('click', function () {
//infoWindow.setContent(links);
// infowindow.open(map, this);
//});
bindInfoWindow(marker, map, infowindow, links);
my_markers.push(marker);
});
}
I have gone through quite a number of related items on Stackoverflow but they don't seem to be of service.They all seem to already have access to the latlang so their structure is different. I have to use the .getJson method to retrieve an addresses latlang first then create markers.