You're setting the content of the same infowindow
for each marker, so it's showing the same one (with the last value it was assigned) no matter which marker is clicked.
Move the line var infowindow = new google.maps.InfoWindow();
to right before infowindow.setContent('<p>'+ prices[i] + '</p>');
and the correct values should appear.
Or, to have a single InfoWindow
shared across all your markers (and therefore allow only one to be visible at a time):
The problem is that you're setting the content of infowindow
when the markers are created rather than when they're clicked. Move the infowindow.setContent('<p>'+ prices[i] + '</p>');
to within the marker click function, right before infowindow.open(map, this);
. In this case, keep the infowindow
declaration where it is.