Both the Map and the StreetViewPanorama require a DIV element that is
already in the DOM in order to render. When creating an InfoWindow,
the content is appended to the DOM asynchronously. Once the elements
have been added to the DOM, we trigger a 'domready' event. At that
point, you can access the DIV you're trying to create, or tell the
StreetViewPanorama to recalculate its size by triggering a 'resize'
event. There are a number of ways to accomplish this, but here are
two examples that accomplish what I think you're after:
var infowindow = new google.maps.InfoWindow({
content: '<div id="sv" style="width:300px;height:200px;"></div>',
position: map.getCenter()
});
infowindow.open(map);
google.maps.event.addListener(infowindow, 'domready', function() {
var panorama = new
google.maps.StreetViewPanorama(document.getElementById("sv"));
panorama.setPosition(infowindow.getPosition());
});
And an alternative:
var streetViewDiv = document.createElement('div');
streetViewDiv.style.width = '300px';
streetViewDiv.style.height = '200px';
var infowindow = new google.maps.InfoWindow({
content: streetViewDiv,
position: map.getCenter()
});
infowindow.open(map);
// The streetViewDiv is not in the DOM yet, so we trigger a resize
event once the InfoWindow is ready.
var panorama = new google.maps.StreetViewPanorama(streetViewDiv,
{position: infowindow.getPosition()});
google.maps.event.addListener(infowindow, 'domready', function() {
google.maps.event.trigger(panorama, 'resize');
});
The second method allows you to use the panorama object even before
the domready event has been triggered.
I hope these examples help.
Susannah