I'm trying to put out markers and info windows from an api with a for loop but only get the last in the list. I have in the for loop because I need to loop through the API and base my information on that. But in my sense I should put out the markers in the loop as well or?
//get all the restaurants which are open
$.getJSON(uri, function(data) {
for(i = 0; i < 5; i++) {
var place = data.response.groups[0].items[i].venue.name;
var placeLat = data.response.groups[0].items[i].venue.location.lat;
var placeLng = data.response.groups[0].items[i].venue.location.lng;
var placeAddress = data.response.groups[0].items[i].venue.location.formattedAddress;
var openPlace = data.response.groups[0].items[i].venue.hours;
var placeGenre = data.response.groups[0].items[i].venue.categories[0].shortName;
console.log(place, placeLat, placeLng, placeAddress, openPlace)
var placePosition = {
lat: placeLat,
lng: placeLng
}
var marker = new google.maps.Marker({
position: placePosition,
map: map
});
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<div><strong>' + place + ' | ' + placeGenre + '</strong><br>' + placeAddress + '<br>' + openPlace + '</div>');
infowindow.open(map, this);
});
}
});
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
}
else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
}
Thanks for the anticipation