The code below works like the nearby function of google maps.It searches and displays the results as markers on a map. If clicked on they also open a infowindow that tells you the name of each locations. The problem I have is that while the markers and made, the infowindows are not. Whatever I'm doing is either causing them not work or not be created. The null reference error appears at this line.

infowindow[q].open( mapArray[i], this);
Code:
function red_button()
{
	for(var i = 0; i < mapArray.length; i++)
	{
		var request = {
		location: markerArray[i],
		radius: 2500,
		types: ['police']
		};	
	
 	 infowindow[i] = new google.maps.InfoWindow();
 	 var service = new google.maps.places.PlacesService(mapArray[i]);
  	 service.nearbySearch(request, callback);
   }
}

function callback(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; i++) {
      createMarker(results[i]);
    }
  }
}

function createMarker(place) {
	
	for(var i = 0; i <  mapArray.length; i++)
	{
		var placeLoc = place.geometry.location;
		var marker = new google.maps.Marker({
		map: mapArray[i],
		position: place.geometry.location
		});
		
		google.maps.event.addListener(marker, 'click', function() {
		for(var q = 0; q <  mapArray.length; q++)
		infowindow[q].setContent(place.name);
		infowindow[q].open( mapArray[i], this);
		});
	}
}
Any thoughts?